QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#544377#8935. Puzzle: Easy as Scrabbleucup-team4821#WA 0ms3644kbC++203.6kb2024-09-02 15:56:022024-09-02 15:56:02

Judging History

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

  • [2024-09-02 15:56:02]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3644kb
  • [2024-09-02 15:56:02]
  • 提交

answer

#include <bits/stdc++.h>
int n, m, L[1005], R[1005], U[1005], D[1005];
char a[1005][1005], l[1005], r[1005], u[1005], d[1005];
std::queue<std::pair<int, int>> que;
void NO()
{
    std::cout << "NO" << std::endl;
    exit(0);
}
void set(int x, int y)
{
    if (a[x][y] != 'x')
    {
        a[x][y] = 'x';
        que.push({x, y});
    }
}
void updatel(int p)
{
    while (L[p] < m && a[p][L[p] + 1] == 'x')
        ++L[p];
    if (l[p] != '.' && L[p] == m)
        NO();
    int q = L[p] + 1;
    if (U[q] + 1 == p && l[p] != '.' && u[q] != '.' && l[p] != u[q])
        set(p, q);
    if (n - D[q] == p && l[p] != '.' && d[q] != '.' && l[p] != d[q])
        set(p, q);
    if (L[p] + R[p] == m - 1 && l[p] != '.' && r[p] != '.' && l[p] != r[p])
        set(p, q);
}
void updater(int p)
{
    while (R[p] < m && a[p][m - R[p]] == 'x')
        ++R[p];
    if (r[p] != '.' && R[p] == m)
        NO();
    int q = m - R[p];
    if (U[q] + 1 == p && r[p] != '.' && u[q] != '.' && r[p] != u[q])
        set(p, q);
    if (n - D[q] == p && r[p] != '.' && d[q] != '.' && r[p] != d[q])
        set(p, q);
    if (L[p] + R[p] == m - 1 && l[p] != '.' && r[p] != '.' && l[p] != r[p])
        set(p, q);
}
void updateu(int q)
{
    while (U[q] < n && a[U[q] + 1][q] == 'x')
        ++U[q];
    if (u[q] != '.' && U[q] == n)
        NO();
    int p = U[q] + 1;
    if (L[p] + 1 == q && u[q] != '.' && l[p] != '.' && u[q] != l[p])
        set(p, q);
    if (m - R[p] == q && u[q] != '.' && r[p] != '.' && u[q] != r[p])
        set(p, q);
    if (U[q] + D[q] == n - 1 && u[q] != '.' && d[q] != '.' && u[q] != d[q])
        set(p, q);
}
void updated(int q)
{
    while (D[q] < n && a[n - D[q]][q] == 'x')
        ++D[q];
    if (d[q] != '.' && D[q] == n)
        NO();
    int p = n - D[q];
    if (L[p] + 1 == q && u[q] != '.' && l[p] != '.' && d[q] != l[p])
        set(p, q);
    if (m - R[p] == q && u[q] != '.' && r[p] != '.' && d[q] != r[p])
        set(p, q);
    if (U[q] + D[q] == n - 1 && u[q] != '.' && d[q] != '.' && u[q] != d[q])
        set(p, q);
}
signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin >> n >> m;
    for (int i = 0; i <= n + 1; ++i)
        for (int j = 0; j <= m + 1; ++j)
            std::cin >> a[i][j];
    for (int i = 1; i <= n; ++i)
        l[i] = a[i][0];
    for (int i = 1; i <= n; ++i)
        r[i] = a[i][m + 1];
    for (int i = 1; i <= m; ++i)
        u[i] = a[0][i];
    for (int i = 1; i <= m; ++i)
        d[i] = a[n + 1][i];
    for (int i = 1; i <= n; ++i)
        updatel(i);
    for (int i = 1; i <= n; ++i)
        updater(i);
    for (int i = 1; i <= m; ++i)
        updateu(i);
    for (int i = 1; i <= m; ++i)
        updated(i);
    while (!que.empty())
    {
        std::pair<int, int> now = que.front();
        que.pop();
        updatel(now.first);
        updater(now.first);
        updateu(now.second);
        updated(now.second);
    }
    for (int i = 1; i <= n; ++i)
        if (l[i] != '.')
            a[i][L[i] + 1] = l[i];
    for (int i = 1; i <= n; ++i)
        if (r[i] != '.')
            a[i][m - R[i]] = r[i];
    for (int i = 1; i <= m; ++i)
        if (u[i] != '.')
            a[U[i] + 1][i] = u[i];
    for (int i = 1; i <= m; ++i)
        if (d[i] != '.')
            a[n - D[i]][i] = d[i];
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            if (a[i][j] == 'x')
                a[i][j] = '.';
    std::cout << "YES" << std::endl;
    for (int i = 1; i <= n; ++i, std::cout << std::endl)
        for (int j = 1; j <= m; ++j)
            std::cout << a[i][j];
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3644kb

input:

5 5
.CBA...
....x..
..x...C
A.....B
B..x..A
C......
.......

output:

YES
CBA..
....C
.A..B
.B..A
.C...

result:

ok Correct.

Test #2:

score: 0
Accepted
time: 0ms
memory: 3516kb

input:

1 2
....
Nx..
..O.

output:

NO

result:

ok Correct.

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3628kb

input:

5 5
.U.N.X.
U....xX
Ox....X
M...xxN
Vx....S
Ix.x..X
..IBHX.

output:

NO

result:

wrong answer Jury has answer but participant has not.