QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#17947#2213. Knightnamelessgugugu#WA 45ms13900kbC++141.7kb2022-01-15 14:03:452022-05-04 16:30:21

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-04 16:30:21]
  • 评测
  • 测评结果:WA
  • 用时:45ms
  • 内存:13900kb
  • [2022-01-15 14:03:45]
  • 提交

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;
}

详细

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