QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#808802#8935. Puzzle: Easy as ScrabbleNoobie_99WA 1ms3568kbC++201.6kb2024-12-11 04:37:252024-12-11 04:37:25

Judging History

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

  • [2024-12-11 04:37:25]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3568kb
  • [2024-12-11 04:37:25]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) ::begin(x), ::end(x)
void _d(auto... x) { ((cerr << ' ' << x), ...) << endl; }
#define debug(x...) cerr << "["#x"]:", _d(x)

int main() {
    cin.tie(0)->sync_with_stdio(0);

    int n, m;
    cin >> n >> m;
    vector<string> a(n+2);
    for (string& e : a) cin >> e;

    vector b = vector(n, vector(m, vector<array<int, 3>>()));
    for (int i=0; i<n; i++) for (int j=0; j<m; j++) {
        if (a[i+1][j+1] == 'x') b[i][j].push_back({0, 0, -1});
    }

    queue<array<int, 5>> q;
    for (int i=0; i<m; i++) if (a[0][i+1] != '.') {
        q.push({0, i, 1, 0, a[0][i+1]});
    }
    for (int i=0; i<m; i++) if (a[n+1][i+1] != '.') {
        q.push({n-1, i, -1, 0, a[n+1][i+1]});
    }
    for (int i=0; i<n; i++) if (a[i+1][0] != '.') {
        q.push({i, 0, 0, 1, a[i+1][0]});
    }
    for (int i=0; i<n; i++) if (a[i+1][m+1] != '.') {
        q.push({i, m-1, 0, -1, a[i+1][m+1]});
    }

    vector<string> ans(n, string(m, '.'));
    while (!q.empty()) {
        auto [x, y, ddx, ddy, cc] = q.front();
        q.pop();
        b[x][y].push_back({ddx, ddy, cc});
        if (ssize(b[x][y]) == 2) {
            for (auto [dx, dy, c] : b[x][y]) if (c != -1) {
                int tx = x + dx, ty = y + dy;
                if (tx < 0 || tx >= n || ty < 0 || ty >= m) {
                    cout << "NO\n";
                    return 0;
                }
                q.push({tx, ty, dx, dy, c});
            }
        } else {
            ans[x][y] = cc;
        }
    }

    cout << "YES\n";
    for (string& e : ans) cout << e << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3560kb

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: 3556kb

input:

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

output:

NO

result:

ok Correct.

Test #3:

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

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.