QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#662833#7733. Cool, It’s Yesterday Four Times Morewxy3265WA 1ms5808kbC++143.3kb2024-10-21 10:59:272024-10-21 10:59:28

Judging History

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

  • [2024-10-21 10:59:28]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5808kb
  • [2024-10-21 10:59:27]
  • 提交

answer

#include <iostream>
#include <string>
#include <map>
#include <queue>
#define int long long
using namespace std;

const int MAXN = 1e3 + 3;
const int MAXC = 5e3 + 3;

int n, m;
char maze[MAXN][MAXN];

struct Node{
    int x, y, i, j;
};

inline bool fall(int x, int y) {
    return x < 1 || y < 1 || x > n || y > m || maze[x][y] == 'O';
}

int cnt;
int color[MAXN][MAXN];
map <pair<int, int>, bool> _map[MAXC];

inline int get(int x, int y, int c) {
    return _map[c][make_pair(x, y)];
}

inline void set(int x, int y, int c, int w) {
    _map[c][make_pair(x, y)] = w;
}

bool vis[MAXN][MAXN];
inline bool bfs(int x, int y, int i, int j) {
    if (_map[color[x][y]].count(make_pair(i, j))) {
//        cout << "get:" << color[x][y] << ' ' << i << ',' << j << ' ' << get(i, j, color[x][y]) << '\n';
        return get(i, j, color[x][y]);
    }
    if (!color[x][y]) cnt++;
    bool able = false;
    for (int k1 = 1; k1 <= n; k1++) for (int k2 = 1; k2 <= m; k2++) vis[k1][k2] = false;
    queue<Node> q;
    q.push(Node{x, y, i, j});
    color[x][y] = cnt;
    vis[x][y] = true;
    while (!q.empty()) {
        Node p = q.front(); q.pop();
        int nx[4] = {0, 1, 0, -1}, ny[4] = {1, 0, -1, 0};
        for (int k = 0; k < 4; k++) {
            int xn = p.x + nx[k], yn = p.y + ny[k];
            int in = p.i + nx[k], jn = p.j + ny[k];
//            cout << xn << ',' << yn << ' ' << in << ',' << jn << '\n';
            if (fall(xn, yn)) {
//                cout << "fall!\n";
                continue;
            }
            if (fall(in, jn)) able = true;
            if (vis[xn][yn]) {
//                cout << "already!\n";
                continue;
            }
            q.push(Node{xn, yn, in, jn});
            vis[xn][yn] = true;
            color[xn][yn] = cnt;
        }
    }
    set(i, j, color[x][y], able);
//    cout << "set:" << color[x][y] << ' ' << i << ',' << j << ' ' << get(i, j, color[x][y]) << '\n';
    return able;
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        cin >> n >> m;
        for (int i = 1; i <= n; i++) {
            string s;
            cin >> s;
            for (int j = 1; j <= m; j++) {
                maze[i][j] = s[j - 1];
                color[i][j] = 0;
            }
        }
        for (int i = 1; i <= cnt; i++) _map[i].clear();
        cnt = 0;
        int ans = 0;
        for (int x = 1; x <= n; x++) {
            for (int y = 1; y <= m; y++) {
                if (fall(x, y)) continue;
                bool able = true;
                for (int i = 1; i <= n; i++) {
                    for (int j = 1; j <= m; j++) {
                        if (fall(i, j) || (i == x && j == y)) continue;
                        if (!bfs(x, y, i, j)) {
                            able = false;
                            break;
                        }
                    }
                    if (!able) break;
                }
                if (able) {
                    ans++;
                }
            }
        }
//        for (int i = 1; i <= n; i++) {
//            for (int j = 1; j <= m; j++) {
//                cout << color[i][j] << ' ';
//            }
//            cout << '\n';
//        }
        cout << ans << '\n';
    }
    return 0;
}

详细

Test #1:

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

input:

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

output:

3
1
0
0

result:

ok 4 lines

Test #2:

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

input:

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

output:

3
0
0
2
1
1
4
0
0
1
0
7
9
4
4
0
6
5
2
0
1
6
5
5
2
0
0
5
3
3
1
4
1
0
7
5
2
3
7
3
0
6
2
2
2
0
4
6
6
4
3
2
3
5
2
1
0
3
3
4
4
2
2
0
7
6
4
8
5
3
2
5
2
1
2
1
4
0
0
2
5
1
4
6
6
1
6
2
2
3
4
5
2
1
0
1
9
3
4
11
0
3
2
1
0
0
4
3
1
4
3
8
2
0
3
6
2
5
1
3
3
4
0
2
11
2
2
4
0
4
4
7
2
1
2
3
0
5
0
16
4
3
2
6
0
8
3
3
1...

result:

wrong answer 7th lines differ - expected: '3', found: '4'