QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#665809 | #7733. Cool, It’s Yesterday Four Times More | 369Pai# | WA | 1ms | 8288kb | C++14 | 2.2kb | 2024-10-22 15:24:08 | 2024-10-22 15:24:13 |
Judging History
answer
#include <bits/stdc++.h>
#define eputchar(c) putc(c, stderr)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define eputs(str) fputs(str, stderr), putc('\n', stderr)
using namespace std;
const int gx[] = {1, -1, 0, 0}, gy[] = {0, 0, -1, 1};
int T, n, m, C, clr[1005][1005], f[1005];
int idx, id[2005][2005];
char c[1005][1005];
vector<int> vec[10005];
int getid(int x, int y) {
if (!id[x + n][y + m]) id[x + n][y + m] = ++idx;
return id[x + n][y + m];
}
int ID(int x, int y) {return (x - 1) * m + y;}
void dfs(int x, int y, int sx, int sy, int cc) {
// if (x == sx && y == sy) eprintf("(%d, %d)\n", sx, sy);
// eprintf("%d %d\n", x - sx, y - sy);
clr[x][y] = cc;
vec[ID(sx, sy)].push_back(getid(x - sx, y - sy));
for (int i = 0; i < 4; i++) {
int xx = x + gx[i], yy = y + gy[i];
if (xx < 1 || xx > n || yy < 1 || yy > m || c[xx][yy] == 'O' || clr[xx][yy] == cc) continue;
dfs(xx, yy, sx, sy, cc);
}
return;
}
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) scanf(" %c", &c[i][j]), clr[i][j] = 0;
idx = 0;
for (int i = -n; i <= n; i++)
for (int j = -m; j <= m; j++) id[i + n][j + m] = 0;
C = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
vec[getid(i, j)].clear();
if (c[i][j] != 'O') dfs(i, j, i, j, ++C);
}
for (int i = 1; i <= n * m; i++) {
sort(vec[i].begin(), vec[i].end()), f[i] = -1;
// eprintf("%d: ", i);
// for (int j : vec[i]) eprintf("%d ", j);
// eputs("");
}
int ans = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
if (c[i][j] == 'O') continue;
int id = ID(i, j);
if (f[clr[i][j]] != -1) {ans += f[clr[i][j]]; continue;}
// eprintf("%d\n", id);
f[clr[i][j]] = 1;
for (int k = 1; k <= n * m; k++)
if (k != id && !vec[k].empty()) {
int flag = 1;
for (int l : vec[id]) {
auto it = lower_bound(vec[k].begin(), vec[k].end(), l);
if (it == vec[k].end() || *it != l) {flag = 0; break;}
}
if (flag) {f[clr[i][j]] = 0; break;}
}
ans += f[clr[i][j]];
}
printf("%d\n", ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6112kb
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: 8288kb
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 0 0 1 3 0 0 1 0 4 9 1 0 0 6 0 0 0 1 6 4 5 0 0 0 5 4 0 1 0 0 0 7 5 0 0 7 0 0 6 0 2 3 0 4 6 6 3 3 3 4 5 2 1 0 3 3 4 4 2 0 2 7 6 0 8 5 3 0 1 0 0 0 1 4 0 0 0 0 1 4 0 6 1 1 2 2 4 6 0 2 1 0 1 9 4 4 11 0 0 0 1 0 0 4 0 1 5 3 10 3 0 3 0 2 5 1 3 3 0 0 0 11 0 2 4 0 4 2 3 0 1 2 0 0 5 0 16 4 3 0 6 0 8 3 3 ...
result:
wrong answer 4th lines differ - expected: '2', found: '0'