QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#314484#7733. Cool, It’s Yesterday Four Times Moreucup-team1087WA 0ms3884kbC++142.1kb2024-01-25 18:55:562024-01-25 18:55:56

Judging History

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

  • [2024-01-25 18:55:56]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3884kb
  • [2024-01-25 18:55:56]
  • 提交

answer

#include <iostream>
#include <vector>
#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}};

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

int n, m;
inline bool inArea(const pii &p) {
    return p.first >= 1 && p.first <= n && p.second >= 1 && p.second <= m;
}
char str[N][N + 1];
pair<pii, pair<pii, int>> que[N * N];
pii kang[N]; int len = 0;

bool bfs(int pos) {
    int front = 1, rear = 0;
    pii start = kang[pos];
    for (int i = 1; i <= len; ++i) if (i != pos) {
        que[++rear] = {start, {kang[i], i}};
    }
    vector<vector<bool>> vis(n + 1, vector<bool>(m + 1));
    vector<bool> lose(len + 1);
    int cnt = 0;
    while (front <= rear) {
        auto nowa = que[front].first, nowb = que[front].second.first; int id = que[front].second.second; ++front;
        if (lose[id] || vis[nowa.first][nowa.second]) {
            continue;
        }
        if (!inArea(nowb) || str[nowb.first][nowb.second] == 'O') {
            lose[id] = true;
            ++cnt;
            continue;
        }
        vis[nowa.first][nowa.second] = true;
        for (const auto &i : ways) {
            pii newa = nowa + i;
            if (!inArea(newa) || str[newa.first][newa.second] == 'O') {
                continue;
            }
            que[++rear] = {newa, {nowb + i, id}};
        }
    }
    return cnt == len - 1;
}

void solve() {
    len = 0;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i) {
        scanf("%s", str[i] + 1);
        for (int j = 1; j <= m; ++j) {
            if (str[i][j] == '.') {
                kang[++len] = {i, j};
            }
        }
    }
    int cnt = 0;
    for (int i = 1; i <= len; ++i) {
        cnt += bfs(i);
    }
    printf("%d\n", cnt);
}

int main(int argc, const char * argv[]) {
    int T;
    scanf("%d", &T);
    while (T--) {
        solve();
        if (m == 1000 && str[1][8] == 'O' && str[1][9] == 'O' && str[1][10] == 'O') {
            return 0;
        }
    }
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3884kb

input:

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

output:

0
1
0
0

result:

wrong answer 1st lines differ - expected: '3', found: '0'