QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#269067 | #7733. Cool, It’s Yesterday Four Times More | mendicillin2# | WA | 1ms | 5456kb | C++17 | 1.6kb | 2023-11-29 11:41:12 | 2023-11-29 11:41:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int a[N][N], vis[N][N];
int cnt = 1;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
struct zzr {
int x, y, ax, ay;
};
queue <zzr> q;
inline int sol(int x, int y, int ax, int ay) {
int sum = 0;
++cnt;
while (!q.empty()) q.pop();
vis[x][y] = cnt;
q.push(zzr{x, y, ax, ay});
while (!q.empty()) {
int tx = q.front().x, ty = q.front().y, ttx = q.front().ax, tty = q.front().ay; q.pop();
++sum;
for (int i = 0; i <= 3; i ++) {
if (a[tx + dx[i]][ty + dy[i]] == 0 || vis[tx + dx[i]][ty + dy[i]] == cnt) continue;
vis[tx + dx[i]][ty + dy[i]] = cnt;
if (ax != 0 && a[ttx + dx[i]][tty + dy[i]] == 0) return 0;
q.push(zzr{tx + dx[i], ty + dy[i], ttx + dx[i], tty + dy[i]});
}
}
if (ax == 0) return sum;
else return 1;
}
inline int solve() {
int n, m; cin >> n >> m;
for (int i = 0; i <= n + 1; i ++)
for (int j = 0; j <= m + 1; j ++)
a[i][j] = vis[i][j] = 0;
int ss = 0;
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= m; j ++) {
char ch;
cin >> ch;
if (ch == 'O') a[i][j] = 0;
else a[i][j] = 1;
ss += a[i][j];
}
if (ss == 1) return 1;
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= m; j ++) {
if (vis[i][j] == cnt || a[i][j] == 0) continue;
int f = 0;
for (int i1 = 1; i1 <= n; i1 ++) {
for (int j1 = 1; j1 <= m; j1 ++)
if (a[i1][j1] && !sol(i, j, i1, j1)) { f = 1; break; }
if (f) break;
}
if (f) return sol(i, j, 0, 0);
}
return 0;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int T; cin >> T;
while (T--) cout << solve() << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5428kb
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: 5456kb
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 2 0 0 1 0 4 9 4 4 0 6 5 2 0 1 6 2 5 2 0 0 5 3 3 1 4 1 0 4 5 2 3 2 3 0 6 2 2 2 0 4 6 6 3 2 2 3 3 2 1 0 3 3 4 4 2 2 2 2 6 4 3 5 3 2 5 2 1 2 1 4 0 0 2 5 1 4 6 3 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 2 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 2 3 2 6 0 8 3 3 1...
result:
wrong answer 7th lines differ - expected: '3', found: '2'