QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#734801#7733. Cool, It’s Yesterday Four Times MoreBIOSOIBWA 1ms5576kbC++202.0kb2024-11-11 15:10:122024-11-11 15:10:13

Judging History

你现在查看的是最新测评结果

  • [2024-11-11 15:10:13]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5576kb
  • [2024-11-11 15:10:12]
  • 提交

answer

#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
const int N = 1e3 + 5;
int id[N][N], idx, n, m, t, res, dx[4] = {0, -1, 0, 1}, dy[4] = {-1, 0, 1, 0};
vector<pair<int, int>> dot[N];
char g[N][N];
bool st[N][N];
void bfs(int sx, int sy, int num)
{
    id[sx][sy] = num;
    queue<pair<int, int>> q;
    q.push({sx, sy});
    while (q.size())
    {
        auto t = q.front();
        q.pop();
        for (int i = 0; i < 4; i++)
        {
            int xx = dx[i] + t.first, yy = dy[i] + t.second;
            if (xx < 1 || xx > n || yy < 1 || yy > m || id[xx][yy] || g[xx][yy] == 'O')
                continue;
            id[xx][yy] = num, dot[num].push_back({xx - sx, yy - sy}), q.push({xx, yy});
        }
    }
}
bool check(int u)
{
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        {
            int num = id[i][j], flag = 1;
            if (g[i][j] == 'O' || num == u || st[u][num])
                continue;
            for (int k = 0; flag && k < dot[u].size(); k++)
            {
                int xx = i + dot[u][k].first, yy = j + dot[u][k].second;
                if (g[xx][yy] == 'O' || id[xx][yy] != num)
                    flag = 0;
            }
            st[u][num] = flag;
        }
    for (int i = 1; i <= idx; i++)
        if (st[u][i])
            return false;
    return true;
}
int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> t;
    while (t--)
    {
        cin >> n >> m, idx = res = 0;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                cin >> g[i][j], id[i][j] = 0, st[i][j] = false;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                if (g[i][j] == '.' && !id[i][j])
                    bfs(i, j, ++idx);
        for (int i = 1; i <= idx; i++)
            if (check(i))
                res += dot[i].size() + 1;
        for (int i = 1; i <= idx; i++)
            dot[i].clear();
        cout << res << "\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5572kb

input:

4
2 5
.OO..
O..O.
1 3
O.O
1 3
.O.
2 3
OOO
OOO

output:

3
1
0
0

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 5576kb

input:

200
2 4
OOO.
OO..
2 3
OOO
.O.
3 3
O.O
OOO
OO.
4 1
.
.
O
O
1 2
.O
1 1
.
2 5
.OO..
.O.O.
2 1
O
O
1 1
O
1 3
.OO
5 1
O
O
.
O
.
5 2
O.
..
O.
.O
..
5 3
...
...
.OO
..O
OOO
3 5
..O.O
.O.O.
.OO.O
5 2
.O
OO
O.
O.
..
2 1
O
O
3 5
.O.OO
O...O
..OO.
1 5
.....
5 1
O
.
O
.
.
5 3
OOO
OO.
.OO
OO.
O.O
2 1
O
.
5 2
O.
...

output:

3
0
0
2
1
1
3
0
0
1
0
7
9
4
4
0
6
5
2
0
1
6
4
5
2
0
0
5
3
3
1
4
1
0
7
5
2
3
7
3
0
6
2
2
2
0
4
6
6
3
0
2
3
5
2
1
0
3
3
4
4
2
2
0
7
6
4
8
5
3
2
5
0
1
2
1
4
0
0
2
5
1
4
6
6
1
6
2
2
3
4
5
2
1
0
1
9
3
4
11
0
3
2
1
0
0
4
3
1
4
3
8
3
0
3
6
2
2
1
3
3
4
0
2
11
2
2
4
0
4
4
6
2
1
2
3
0
5
0
16
4
3
2
6
0
8
3
3
1...

result:

wrong answer 51st lines differ - expected: '3', found: '0'