代码卡常求助

求卡常:

#include <bits/stdc++.h>
using namespace std;
int n, m;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int pts;
long long ans = 0;
bool vis[105][105];
char mp[105][105];
pair<int, int> LftTop, RghBtm;
void bfs(int x, int y)
{
    queue<pair<int, int>> q;
    pts = 0;
    LftTop = {INT_MAX, INT_MAX}, RghBtm = {INT_MIN, INT_MIN};
    vis[x][y] = 1;
    q.push({x, y});
    while (!q.empty())
    {
        auto tp = q.front();
        q.pop();
        pts++;
        LftTop = min(LftTop, tp);
        RghBtm = max(RghBtm, tp);
        for (int i = 0; i < 4; i++)
        {
            auto tx = tp.first + dx[i], ty = tp.second + dy[i];
            if (tx < 0 || ty < 0 || tx >= n || ty >= m)
                continue;
            if (vis[tx][ty] || mp[tx][ty] != ' ')
                continue;
            vis[tx][ty] |= 1;
            q.push({tx, ty});
        }
    }
}
int main()
{
    cin.tie(&cout)->sync_with_stdio(0);
    string tmp, sn, sm;
    getline(cin, tmp);
    istringstream iss(tmp + ' ');
    getline(iss, sn, ' ');
    getline(iss, sm, ' ');
    n = stoi(sn), m = stoi(sm);
    for (int i = 0; i < n; i++)
    {
        getline(cin, tmp);
        for (int j = 0; j < m; j++)
        {
            mp[i][j] = tmp[j];
        }
    }
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            if (!vis[i][j] && mp[i][j] == ' ')
            {
                bfs(i, j);
                if ((RghBtm.first - LftTop.first + 1) < 3 || (RghBtm.first - LftTop.first + 1) > 23 || (RghBtm.second - LftTop.second + 1) < 2 || (RghBtm.second - LftTop.second + 1) > 23)
                    continue;
                if (pts == (RghBtm.first - LftTop.first + 1) * (RghBtm.second - LftTop.second + 1))
                    ans++;
            }
    cout << ans;
    return 0;
}

加个快读快写

这里咋用,这是一行读入
用了scanf("%[^\n]%*c")就WA

莫名WA

本来是对的吗

用getline是对的
改getchar:
image

那就加register

*哪里加

循环中i或j的定义

比如:

改成
for(register int i = 0; i < n; i++)

分数没变

还是WA?

是的

题面

image

链接发一个

私有题目好像没有权限看吧(T574766)

有的

更新了(公众可见
image

啊?你这代码我一交就过了