QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#662824 | #5414. Stop, Yesterday Please No More | wxy3265 | WA | 1ms | 3808kb | C++14 | 3.3kb | 2024-10-21 10:55:26 | 2024-10-21 10:55:26 |
Judging History
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];
}
}
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3808kb
input:
3 4 5 3 ULDDRR 4 5 0 UUUUUUU 4 5 10 UUUUUUU
output:
20 0 0
result:
wrong answer 1st numbers differ - expected: '2', found: '20'