求助一道站外题
  • 板块灌水区
  • 楼主FiraCode
  • 当前回复8
  • 已保存回复8
  • 发布时间2022/9/11 22:35
  • 上次更新2023/10/27 11:55:49
查看原帖
求助一道站外题
528430
FiraCode楼主2022/9/11 22:35

只有50分,求助。

那个大佬帮我康康

CODE

#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
int n, m;
char a[110][110];
bool color(int x, int y, char col) {
    a[x][y] = col;
    for (int i = 0; i < 4; ++i) {
        int tx = x + dx[i];
        int ty = y + dy[i];
        if (tx > n || tx < 1 || ty > m || ty < 1)
            continue;
        if (a[tx][ty] == '?') {
            char c;
            if (col == 'B')
                c = 'W';
            else
                c = 'B';
            if (!color(tx, ty, c))return false;
        }else {
            if (a[tx][ty] == col)
                return false;
        }
    }
    return true;
}
int main() {
    while (~scanf("%d%d", &n, &m)) {
        for (int i = 1; i <= n; ++i)
            scanf("%s", a[i] + 1);
        int x = 1, y = 1;
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= m; ++j) {
                if (a[i][j] != '?') {
                    x = i, y = j;
                    break;
                }
            }
        if (a[x][y] == '?')
            a[x][y] = 'B';
        if (!color(x, y, a[x][y]))
            puts("Impossible");
        else
            puts("Possible");
    }
    return 0;
}
time: 17ms, memory: 364kb, score: 50, status: Wrong Answer
> test 0: time: 3ms, memory: 364kb, points: 10, status: Accepted
> test 1: time: 2ms, memory: 364kb, points: 0, status: Wrong Answer
> test 2: time: 0ms, memory: 364kb, points: 0, status: Wrong Answer
> test 3: time: 0ms, memory: 364kb, points: 10, status: Accepted
> test 4: time: 3ms, memory: 364kb, points: 0, status: Wrong Answer
> test 5: time: 3ms, memory: 364kb, points: 10, status: Accepted
> test 6: time: 1ms, memory: 364kb, points: 0, status: Wrong Answer
> test 7: time: 3ms, memory: 364kb, points: 0, status: Wrong Answer
> test 8: time: 1ms, memory: 364kb, points: 10, status: Accepted
> test 9: time: 1ms, memory: 364kb, points: 10, status: Accepted
2022/9/11 22:35
加载中...