QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#666165#7733. Cool, It’s Yesterday Four Times MoretzwWA 2ms9920kbC++232.9kb2024-10-22 16:53:512024-10-22 16:53:53

Judging History

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

  • [2024-10-22 16:53:53]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9920kb
  • [2024-10-22 16:53:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
char c[1010][1010];
int vis[1010][1010], n, m, ans, cnt, sum[1000010], b[4][2] = { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 } };
pair<int, int> pr[1000010];
void dfs(int x, int y)
{
    if (x < pr[cnt].first)
        pr[cnt] = { x, y };
    else if (x == pr[cnt].first && y < pr[cnt].second)
        pr[cnt] = { x, y };
    vis[x][y] = cnt;
    sum[cnt]++;
    for (int i = 0; i < 4; i++) {
        int ux = x + b[i][0], uy = y + b[i][1];
        if (ux > n || ux < 1 || uy > m || uy < 1)
            continue;
        if (!vis[ux][uy] && c[ux][uy] == '.')
            dfs(ux, uy);
    }
}
void solve()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> c[i][j];
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (!vis[i][j] && c[i][j] == '.') {
                cnt++;
                pr[cnt].first = i, pr[cnt].second = j;
                dfs(i, j);
                ans = max(ans, sum[cnt]);
            }
        }
    }
    int flag = 0;
    for (int i = 1; i <= cnt; i++)
        if (sum[i] == ans)
            flag++;
    if (flag == 1)
        cout << ans << endl;
    else if (flag > 1 && ans > 1) {
        vector<int> v;
        for (int i = 1; i <= cnt; i++) {
            if (sum[i] == ans)
                v.push_back(i);
        }
        ans = 0;
        for (int i = 0; i < v.size(); i++) {
            bool flag1 = 1;
            for (int j = 0; j < v.size(); j++) {
                bool flag2 = 1;
                if (i == j)
                    continue;
                for (int x1 = 1; x1 <= n; x1++) {
                    for (int y1 = 1; y1 <= m; y1++) {
                        if (vis[x1][y1] == i) {
                            int x2 = x1 - pr[i].first + pr[j].first, y2 = y1 - pr[i].second + pr[j].second;
                            if (x2 > n || x2 < 1 || y2 > m || y2 < 1) {
                                flag2 = 0;
                                break;
                            } else if (vis[x2][y2] != j) {
                                flag2 = 0;
                                break;
                            }
                        }
                    }
                }
                if (flag2)
                    flag1 = 0;
            }
            if (flag1)
                ans += sum[i];
        }
        cout << ans << endl;
    } else
        cout << 0 << endl;
    for (int i = 1; i <= cnt; i++) {
        pr[i] = { 0, 0 };
        sum[i] = 0;
    }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            vis[i][j] = 0;
    cnt = 0;
    ans = 0;
}
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 7656kb

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: 0ms
memory: 9920kb

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
4
9
4
4
0
6
5
2
0
1
6
4
5
2
0
0
5
3
3
1
4
1
0
4
5
2
3
7
3
0
6
2
2
2
0
4
6
6
3
3
2
3
3
2
1
0
3
3
4
4
2
2
2
7
6
4
8
5
3
2
5
2
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
3
2
3
1
3
3
4
0
2
11
2
2
4
0
4
2
3
2
1
2
3
0
5
0
16
4
3
2
6
0
8
3
3
1...

result:

wrong answer 12th lines differ - expected: '7', found: '4'