QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#17947 | #2213. Knight | namelessgugugu# | WA | 45ms | 13900kb | C++14 | 1.7kb | 2022-01-15 14:03:45 | 2022-05-04 16:30:21 |
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)
{
int fx = find(x), fy = find(y);
if (fx == fy)
return;
fa[fx] = fy, siz[fy] += siz[fx], val[fx] = !val[x];
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: 12ms
memory: 13296kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 5864kb
Test #3:
score: 0
Accepted
time: 45ms
memory: 13900kb
Test #4:
score: -100
Wrong Answer
time: 36ms
memory: 13228kb