QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#402714#6398. Puzzle: TapaiwewWA 1ms3784kbC++206.3kb2024-05-01 11:29:212024-05-01 11:29:22

Judging History

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

  • [2024-05-01 11:29:22]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3784kb
  • [2024-05-01 11:29:21]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 10010;

int n, m;
string s[110];
bool vis[N];

vector<int> adj[N];

int dfs0(int u, int fa, int color) {
    int res = 1;
    vis[u] = true;
    for(auto v : adj[u]) {
        if(v == fa || vis[v]) continue;
        res += dfs0(v, u, color ^ 1);
        if(color == 0) {
            int xu = (u / m) * 2, yu = (u % m) * 2;
            int xv = (v / m) * 2, yv = (v % m) * 2;
            if(xu == xv) {
                s[xu][(yu + yv) / 2] = '.';
            } else if(yu == yv) {
                s[(xu + xv) / 2][yu] = '.';
            }
        }
    }
    return res;
}

bool dfs1(int u, int fa, int color) {
    vis[u] = true;
    vector<int> son;
    for(auto v : adj[u]) {
        if(v == fa || vis[v]) continue;
        if(!dfs1(v, u, color ^ 1)) return false;
        son.push_back(v);
    }
    if(color == 0) {
        if((int)son.size() == 1) {
            int v = son[0];
            int xu = (u / m) * 2, yu = (u % m) * 2;
            int xv = (v / m) * 2, yv = (v % m) * 2;
            if(xu == xv) {
                s[xu][(yu + yv) / 2] = '.';
            } else if(yu == yv) {
                s[(xu + xv) / 2][yu] = '.';
            }
        } else if((int)son.size() == 3) {
            int xu = (u / m) * 2, yu = (u % m) * 2;
            s[xu + 1][yu + 1] = '.';
        } else {
            return false;
        }
    }
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m;
    vector<vector<int>> a(n, vector<int> (m));
    for(int i = 0; i < 2 * n - 1; i ++ ) cin >> s[i];
    for(int i = 0; i < n; i ++ ) {
        for(int j = 0; j < m; j ++ ) {
            int x = 2 * i, y = 2 * j;
            a[i][j] = s[x][y] - '0';
        }
    }

    vector<vector<int>> b(n, vector<int> (m, 0));
    b[0][0] = b[0][m - 1] = b[n - 1][0] = b[n - 1][m - 1] = 3;
    for(int i = 1; i < m - 1; i ++ ) b[0][i] = b[n - 1][i] = 5;
    for(int i = 1; i < n - 1; i ++ ) b[i][0] = b[i][m - 1] = 5;
    for(int i = 1; i < n - 1; i ++ ) {
        for(int j = 1; j < m - 1; j ++ ) {
            b[i][j] = 8;
        }
    }

    // for(int i = 0; i < n; i ++ ) {
    //     for(int j = 0; j < m; j ++ ) {
    //         cout << a[i][j] << ' ';
    //     }
    //     cout << '\n';
    // }
    // cout << '\n';
    // for(int i = 0; i < n; i ++ ) {
    //     for(int j = 0; j < m; j ++ ) {
    //         cout << b[i][j] << ' ';
    //     }
    //     cout << '\n';
    // }
    // cout << '\n';

    auto addedge = [&](int u, int v) -> void {
        adj[u].push_back(v);
    };

    vector<int> seq0, seq1;
    if(a[0][0] != b[0][0]) {
        if(a[0][1] != b[0][1]) addedge(0, 1);
        if(a[1][0] != b[1][0]) addedge(0, m);
        seq0.push_back(0);
    }
    if(a[0][m - 1] != b[0][m - 1]) {
        if(a[0][m - 2] != b[0][m - 2]) addedge(m - 1, m - 2);
        if(a[1][m - 1] != b[1][m - 1]) addedge(m - 1, m + m - 1);
        seq0.push_back(m - 1);
    }
    if(a[n - 1][0] != b[n - 1][0]) {
        if(a[n - 2][0] != b[n - 2][0]) addedge((n - 1) * m, (n - 2) * m);
        if(a[n - 1][1] != b[n - 1][1]) addedge((n - 1) * m, (n - 1) * m + 1);
        seq0.push_back((n - 1) * m);
    }
    if(a[n - 1][m - 1] != b[n - 1][m - 1]) {
        if(a[n - 2][m - 1] != b[n - 2][m - 1]) addedge((n - 1) * m + m - 1, (n - 2) * m + m - 1);
        if(a[n - 1][m - 2] != b[n - 1][m - 2]) addedge((n - 1) * m + m - 1, (n - 1) * m + m - 2);
        seq0.push_back((n - 1) * m + m - 1);
    }
    for(int i = 1; i < m - 1; i ++ ) {
        if(a[0][i] != b[0][i]) {
            if(a[0][i - 1] != b[0][i - 1]) addedge(i, i - 1);
            if(a[0][i + 1] != b[0][i + 1]) addedge(i, i + 1);
            seq0.push_back(i);
        }
        if(a[n - 1][i] != b[n - 1][i]) {
            if(a[n - 1][i - 1] != b[n - 1][i - 1]) addedge((n - 1) * m + i, (n - 1) * m + i - 1);
            if(a[n - 1][i + 1] != b[n - 1][i + 1]) addedge((n - 1) * m + i, (n - 1) * m + i + 1);
            seq0.push_back((n - 1) * m + i);
        }
    }
    for(int i = 1; i < n - 1; i ++ ) {
        if(a[i][0] != b[i][0]) {
            if(a[i - 1][0] != b[i - 1][0]) addedge(i * m, (i - 1) * m);
            if(a[i + 1][0] != b[i + 1][0]) addedge(i * m, (i + 1) * m);
            seq0.push_back(i * m);
        }
        if(a[i][m - 1] != b[i][m - 1]) {
            if(a[i - 1][m - 1] != b[i - 1][m - 1]) addedge(i * m + m - 1, (i - 1) * m + m - 1);
            if(a[i + 1][m - 1] != b[i + 1][m - 1]) addedge(i * m + m - 1, (i + 1) * m + m - 1);
            seq0.push_back(i * m + m - 1);
        }
    }

    vector<int> dx = {0, 1, 1};
    vector<int> dy = {1, 0, 1};
    for(int i = 1; i < n - 1; i ++ ) {
        for(int j = 1; j < m - 1; j ++ ) {
            for(int dir = 0; dir < 3; dir ++ ) {
                int x = i + dx[dir], y = j + dy[dir];
                if(x >= 1 && x < n - 1 && y >= 1 && y < m - 1) {
                    if(a[i][j] != b[i][j] && a[x][y] != b[x][y]) {
                        addedge(i * m + j, x * m + y);
                        seq1.push_back(i * m + j);
                    }
                }
            }
        }
    }

    sort(seq1.begin(), seq1.end());
    seq1.erase(unique(seq1.begin(), seq1.end()), seq1.end());

    for(int i = 0; i < 2 * n - 1; i ++ ) {
        for(int j = 0; j < 2 * m - 1; j ++ ) {
            if(s[i][j] == '.') {
                s[i][j] = '#';
            }
        }
    }

    bool ok = true, has = false;
    for(auto x : seq0) {
        if(!vis[x] && (int)adj[x].size() <= 1) {
            has = true;
            if(dfs0(x, -1, 0) % 2) {
                ok = false;
                break;
            }
        }
    }
    // for(auto x : seq0) cout << x << ' ';
    // cout << '\n';
    // for(auto x : seq1) cout << x << ' ';
    // cout << '\n';
    // cout << "ooo  " << ok << endl;
    if((int)seq0.size() && !has) dfs0(seq0[0], -1, 0);
    for(auto x : seq1) {
        if(!vis[x]) {
            if(!dfs1(x, -1, 0)) {
                ok = false;
                break;
            }
        }
    }
    if(ok) {
        cout << "YES" << '\n';
        for(int i = 0; i < 2 * n - 1; i ++ ) {
            cout << s[i] << '\n';
        }
    } else {
        cout << "NO" << '\n';
    }
    return 0;
}

詳細信息

Test #1:

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

input:

3 3
2.4.3
.....
5.8.5
.....
3.5.3

output:

YES
2.4#3
#####
5#8#5
#####
3#5#3

result:

ok Correct.

Test #2:

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

input:

3 3
3.4.3
.....
5.7.5
.....
3.5.3

output:

NO

result:

ok Correct.

Test #3:

score: 0
Accepted
time: 1ms
memory: 3488kb

input:

2 2
2.2
...
2.2

output:

YES
2.2
###
2.2

result:

ok Correct.

Test #4:

score: 0
Accepted
time: 1ms
memory: 3552kb

input:

2 50
2.4.4.4.4.5.5.5.5.5.5.5.5.4.5.5.4.4.5.5.5.5.4.5.5.5.5.5.4.4.5.4.5.5.5.5.5.5.5.5.5.5.5.4.4.5.5.4.5.3
...................................................................................................
2.5.5.4.4.5.5.5.4.4.5.5.5.4.5.5.5.5.5.5.5.5.4.4.4.5.5.5.5.5.5.4.4.4.5.5.5.5.5.5.5.4.4.5.5.5.5.4...

output:

NO

result:

ok Correct.

Test #5:

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

input:

2 50
2.4.4.5.5.5.5.5.5.5.5.5.4.4.5.5.5.5.4.4.5.5.4.4.5.5.5.4.5.4.4.4.5.4.4.5.4.4.5.5.5.5.4.4.5.5.5.5.5.2
...................................................................................................
3.5.4.5.5.5.5.5.5.5.5.5.5.5.4.5.5.5.5.4.5.5.5.5.4.4.5.4.5.4.5.5.5.5.5.4.4.5.5.5.4.4.5.5.5.5.5.4...

output:

NO

result:

ok Correct.

Test #6:

score: 0
Accepted
time: 1ms
memory: 3556kb

input:

50 2
3.2
...
5.4
...
5.5
...
4.4
...
5.5
...
5.5
...
5.5
...
5.5
...
5.5
...
5.5
...
5.5
...
5.4
...
5.4
...
5.5
...
5.5
...
5.5
...
5.5
...
5.5
...
5.4
...
5.4
...
5.4
...
5.4
...
4.4
...
5.5
...
5.5
...
4.4
...
5.4
...
5.4
...
5.5
...
4.5
...
4.5
...
5.5
...
5.5
...
5.5
...
5.5
...
5.5
...
5.5
......

output:

NO

result:

ok Correct.

Test #7:

score: 0
Accepted
time: 1ms
memory: 3752kb

input:

50 2
3.3
...
5.4
...
5.4
...
5.4
...
5.4
...
5.5
...
4.4
...
4.4
...
5.5
...
4.4
...
5.5
...
5.5
...
5.5
...
5.5
...
4.5
...
5.5
...
5.5
...
5.4
...
5.4
...
5.5
...
5.4
...
5.5
...
5.4
...
5.4
...
5.5
...
5.5
...
4.5
...
4.5
...
4.5
...
4.5
...
5.5
...
5.4
...
5.4
...
5.5
...
5.5
...
4.4
...
4.4
......

output:

NO

result:

ok Correct.

Test #8:

score: 0
Accepted
time: 1ms
memory: 3620kb

input:

3 50
3.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.5.4.4.5.5.5.5.4.4.5.5.5.5.5.5.5.5.4.4.5.5.4.4.5.4.4.5.3
...................................................................................................
4.8.8.8.8.8.8.8.8.8.8.8.8.8.8.7.7.7.7.7.7.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.8.7.7.8...

output:

YES
3#5#5#5#5#5#5#5#5#5#5#5#5#5#5#5#5#5#5#5#5#5#5#4.4#5#5#5#5#4.4#5#5#5#5#5#5#5#5#4.4#5#5#4.4#5#4.4#5#3
###################################################################################################
4#8#8#8#8#8#8#8#8#8#8#8#8#8#8#7.7#7.7#7.7#8#8#8#8#8#8#8#8#8#8#8#8#8#8#8#8#8#8#8#8#8#8#8#8#7.7#8#...

result:

ok Correct.

Test #9:

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

input:

3 50
2.4.4.4.5.4.4.4.4.4.4.5.5.4.4.5.5.4.4.5.5.5.4.4.5.5.5.4.4.5.5.4.4.4.4.5.5.5.5.5.5.4.4.5.5.5.5.4.4.3
...................................................................................................
5.7.7.8.7.7.7.7.8.8.8.8.7.7.8.7.7.8.8.8.8.7.7.8.8.8.7.7.8.7.7.8.8.8.8.7.7.8.8.7.7.8.8.8.7.7.8.8...

output:

YES
2.4#4.4#5#4.4#4.4#4.4#5#5#4.4#5#5#4.4#5#5#5#4.4#5#5#5#4.4#5#5#4.4#4.4#5#5#5#5#5#5#4.4#5#5#5#5#4.4#3
###################################################################################################
5#7.7#8#7.7#7.7#8#8#8#8#7.7#8#7.7#8#8#8#8#7.7#8#8#8#7.7#8#7.7#8#8#8#8#7.7#8#8#7.7#8#8#8#7.7#8#8#...

result:

ok Correct.

Test #10:

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

input:

50 3
3.5.3
.....
5.8.5
.....
5.8.5
.....
5.8.5
.....
5.8.5
.....
5.8.5
.....
5.8.4
.....
5.8.4
.....
4.8.5
.....
4.7.5
.....
5.7.5
.....
5.8.5
.....
5.8.4
.....
5.8.4
.....
5.8.5
.....
5.8.5
.....
5.8.5
.....
5.8.5
.....
5.8.5
.....
4.8.5
.....
4.7.5
.....
5.7.5
.....
5.8.5
.....
5.8.5
.....
5.8.5
....

output:

YES
3#5#3
#####
5#8#5
#####
5#8#5
#####
5#8#5
#####
5#8#5
#####
5#8#5
#####
5#8#4
####.
5#8#4
#####
4#8#5
.####
4#7#5
##.##
5#7#5
#####
5#8#5
#####
5#8#4
####.
5#8#4
#####
5#8#5
#####
5#8#5
#####
5#8#5
#####
5#8#5
#####
5#8#5
#####
4#8#5
.####
4#7#5
##.##
5#7#5
#####
5#8#5
#####
5#8#5
#####
5#8#5
##...

result:

ok Correct.

Test #11:

score: 0
Accepted
time: 1ms
memory: 3504kb

input:

50 3
2.4.3
.....
4.8.5
.....
4.8.5
.....
5.8.5
.....
4.7.4
.....
4.7.4
.....
4.8.5
.....
4.8.4
.....
5.8.4
.....
4.7.5
.....
4.7.5
.....
5.8.5
.....
5.8.5
.....
5.8.4
.....
5.8.4
.....
5.8.5
.....
5.8.5
.....
5.7.5
.....
5.7.5
.....
5.8.5
.....
5.8.5
.....
5.8.5
.....
4.8.5
.....
4.7.5
.....
4.7.4
....

output:

YES
2.4#3
#####
4#8#5
.####
4#8#5
#####
5#8#5
#####
4#7#4
.#.#.
4#7#4
#####
4#8#5
.####
4#8#4
####.
5#8#4
#####
4#7#5
.#.##
4#7#5
#####
5#8#5
#####
5#8#5
#####
5#8#4
####.
5#8#4
#####
5#8#5
#####
5#8#5
#####
5#7#5
##.##
5#7#5
#####
5#8#5
#####
5#8#5
#####
5#8#5
#####
4#8#5
.####
4#7#5
##.##
4#7#4
.#...

result:

ok Correct.

Test #12:

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

input:

10 10
2.4.4.4.5.5.4.4.5.2
...................
5.7.8.8.7.8.7.7.8.4
...................
4.7.8.8.7.8.8.8.8.5
...................
4.8.8.8.7.7.8.8.8.4
...................
5.8.7.7.7.7.8.8.7.4
...................
4.7.7.8.8.8.8.8.7.4
...................
4.8.7.8.8.7.7.7.8.4
...................
5.8.7.8.8.7.8....

output:

NO

result:

wrong answer Jury has answer but participant has not.