QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#610070 | #7733. Cool, It’s Yesterday Four Times More | LittleYoo | RE | 0ms | 3612kb | C++20 | 2.0kb | 2024-10-04 14:51:44 | 2024-10-04 14:51:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
vector<pair<int, int>> dir = {
{1, 0},
{-1, 0},
{0, -1},
{0, 1}
};
void solve()
{
int n, m;
cin >> n >> m;
vector a(n + 2, vector<char>(m + 2, 'O'));
int tot = 0;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j) {
cin >> a[i][j];
tot += a[i][j] == '.';
}
auto get = [&](int x, int y) { return (x - 1) * m + y - 1; };
auto get2 = [&](int x, int y) { return x * (m * 2 + 1) + y; };
vector<bitset<1005>> f(n * m + 1);
vector rec(8 * n * m, vector<int>());
auto bfs = [&](int x, int y) {
queue<pair<int, int>> q;
vector vis(n + 2, vector<int>(m + 2));
vis[x][y] = 1;
q.emplace(0, 0);
while(!q.empty()) {
auto [dx, dy] = q.front();
rec[get2(dx + n, dy + m)].emplace_back(get(x, y));
q.pop();
for(auto &[ddx, ddy] : dir) {
int sx = x + dx + ddx, sy = y + dy + ddy;
if(vis[sx][sy] || a[sx][sy] == 'O')
continue;
vis[sx][sy] = 1;
q.emplace(dx + ddx, dy + ddy);
}
}
};
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
if(a[i][j] == '.')
bfs(i, j);
for(int i = 0; i <= n * 2; ++i)
for(int j = 0; j <= m * 2; ++j)
if(int cur = get2(i, j); !rec[cur].empty()) {
// cerr << "OK\n";
bitset<1005> winner;
for(auto &c : rec[cur])
winner[c] = 1;
for(int c = 0; c < n * m; ++c)
if(winner[c])
for(int ii = 1; ii <= n; ++ii)
for(int jj = 1; jj <= m; ++jj)
if(a[ii][jj] == '.' && !winner[get(ii, jj)])
f[c][get(ii, jj)] = 1;
}
auto ok = [&](int x, int y) {
return f[get(x, y)].count() == tot - 1;
};
int ans = 0;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
if(a[i][j] == '.')
ans += ok(i, j);
cout << ans << '\n';
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T = 1;
cin >> T;
while(T--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
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
Runtime Error
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. ...