QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#314582#7733. Cool, It’s Yesterday Four Times Moreucup-team1087WA 1ms3792kbC++142.3kb2024-01-25 20:56:052024-01-25 20:56:06

Judging History

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

  • [2024-01-25 20:56:06]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3792kb
  • [2024-01-25 20:56:05]
  • 提交

answer

#include <iostream>
#include <queue>
#include <cassert>
using namespace std;
typedef pair<int, int> pii;

const int N = 1e3 + 1;
const int ways[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

int n, m;
inline bool inArea(const pii &p) {
    return p.first >= 1 && p.first <= n && p.second >= 1 && p.second <= m;
}

inline pii operator + (const pii &p, const int a[2]) {
    return {p.first + a[0], p.second + a[1]};
}

char str[N][N + 1];

void solve() {
    scanf("%d%d", &n, &m);
    vector<pii> kang, hole;
    for (int i = 1; i <= n; ++i) {
        scanf("%s", str[i] + 1);
    }
    for (int i = 0; i <= n + 1; ++i) {
        for (int j = 0; j <= m + 1; ++j) {
            if (i == 0 || i == n + 1 || j == 0 || j == m + 1) {
                hole.emplace_back(i, j);
                continue;
            }
            if (str[i][j] == '.') {
                kang.emplace_back(i, j);
            } else {
                hole.emplace_back(i, j);
            }
        }
    }
    queue<pair<pii, pii>> que;
    vector<vector<vector<vector<bool>>>> dp(n + 2, vector<vector<vector<bool>>>(m + 2, vector<vector<bool>>(n + 2, vector<bool>(m + 2))));
    for (auto [x, y] : kang) {
        for (auto [i, j] : hole) {
            dp[x][y][i][j] = true;
            que.push({{x, y}, {i, j}});
        }
    }
    while (!que.empty()) {
        auto [nowa, nowb] = que.front(); que.pop();
        for (const auto &i : ways) {
            auto newa = nowa + i, newb = nowb + i;
            if (!inArea(newa) || !inArea(newb) || str[newa.first][newa.second] != '.' || str[newb.first][newb.second] != '.') {
                continue;
            }
            if (!dp[newa.first][newa.second][newb.first][newb.second]) {
                dp[newa.first][newa.second][newb.first][newb.second] = true;
                que.push({newa, newb});
            }
        }
    }
    int ans = 0;
    for (auto [x, y] : kang) {
        bool flag = true;
        for (auto [i, j] : kang) if (x != i && y != j) {
            if (!dp[x][y][i][j]) {
                flag = false;
                break;
            }
        }
        ans += flag;
    }
    printf("%d\n", ans);
}

int main(int argc, const char * argv[]) {
    int T;
    scanf("%d", &T);
    while (T--) {
        solve();
    }
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3792kb

input:

4
2 5
.OO..
O..O.
1 3
O.O
1 3
.O.
2 3
OOO
OOO

output:

3
1
2
0

result:

wrong answer 3rd lines differ - expected: '0', found: '2'