QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#17946 | #2213. Knight | namelessgugugu# | WA | 54ms | 14324kb | C++14 | 1.7kb | 2022-01-15 13:59:59 | 2022-05-04 16:30:18 |
Judging History
answer
#include <algorithm>
#include <cstdio>
#include <cstring>
const int N = 1005;
int n, m, r, c, pa, pb;
char s[N][N];
int fa[N * N], val[N * N], siz[N * N];
inline int find(int x)
{
if (fa[x] == x)
return x;
int res = find(fa[x]);
val[x] ^= val[fa[x]];
return fa[x] = res;
}
inline void merge(int x, int y)
{
x = find(x), y = find(y);
if (x == y)
return;
fa[x] = y, siz[y] += siz[x], val[x] = 1;
return;
}
int main(void)
{
scanf("%d%d%d%d", &n, &m, &r, &c);
for (int i = 1; i <= n; ++i)
scanf("%s", s[i] + 1);
int dx[] = {r, r, -r, -r, c, c, -c, -c};
int dy[] = {c, -c, c, -c, r, -r, r, -r};
for (int i = 1; i <= n * m; ++i)
fa[i] = i, val[i] = 0, siz[i] = 1;
for (int x = 1; x <= n; ++x)
for (int y = 1; y <= m; ++y)
if (s[x][y] != '@')
{
for (int k = 0; k < 8; ++k)
{
int nx = x + dx[k], ny = y + dy[k];
if (nx < 1 || ny < 1 || nx > n || ny > m || s[nx][ny] == '@')
continue;
merge((x - 1) * m + y, (nx - 1) * m + ny);
}
}
for (int x = 1; x <= n; ++x)
for (int y = 1; y <= m; ++y)
if (s[x][y] == 'A')
{
pa = (x - 1) * m + y;
}
else if (s[x][y] == 'B')
{
pb = (x - 1) * m + y;
}
if (siz[find(pa)] == 1)
return puts("Bob"), 0;
if (find(pa) != find(pb))
return puts("Alice"), 0;
find(pa), find(pb);
puts(val[pa] == val[pb] ? "Alice" : "Bob");
return 0;
}
Details
Test #1:
score: 100
Accepted
time: 16ms
memory: 14076kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 5936kb
Test #3:
score: 0
Accepted
time: 39ms
memory: 13208kb
Test #4:
score: 0
Accepted
time: 37ms
memory: 14324kb
Test #5:
score: 0
Accepted
time: 1ms
memory: 7808kb
Test #6:
score: 0
Accepted
time: 9ms
memory: 9052kb
Test #7:
score: 0
Accepted
time: 3ms
memory: 5704kb
Test #8:
score: 0
Accepted
time: 3ms
memory: 10728kb
Test #9:
score: 0
Accepted
time: 21ms
memory: 13476kb
Test #10:
score: 0
Accepted
time: 7ms
memory: 13848kb
Test #11:
score: 0
Accepted
time: 9ms
memory: 7228kb
Test #12:
score: 0
Accepted
time: 24ms
memory: 14164kb
Test #13:
score: 0
Accepted
time: 9ms
memory: 10304kb
Test #14:
score: 0
Accepted
time: 17ms
memory: 13368kb
Test #15:
score: 0
Accepted
time: 3ms
memory: 6792kb
Test #16:
score: 0
Accepted
time: 8ms
memory: 14212kb
Test #17:
score: 0
Accepted
time: 2ms
memory: 9836kb
Test #18:
score: 0
Accepted
time: 4ms
memory: 12004kb
Test #19:
score: 0
Accepted
time: 6ms
memory: 7988kb
Test #20:
score: 0
Accepted
time: 5ms
memory: 13448kb
Test #21:
score: 0
Accepted
time: 1ms
memory: 7656kb
Test #22:
score: 0
Accepted
time: 3ms
memory: 8920kb
Test #23:
score: 0
Accepted
time: 3ms
memory: 7816kb
Test #24:
score: 0
Accepted
time: 4ms
memory: 13656kb
Test #25:
score: 0
Accepted
time: 6ms
memory: 7100kb
Test #26:
score: 0
Accepted
time: 0ms
memory: 7804kb
Test #27:
score: 0
Accepted
time: 0ms
memory: 7748kb
Test #28:
score: -100
Wrong Answer
time: 54ms
memory: 11508kb