QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#609974 | #7733. Cool, It’s Yesterday Four Times More | LittleYoo | RE | 0ms | 0kb | C++20 | 1.9kb | 2024-10-04 14:37:00 | 2024-10-04 14:37:03 |
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}
};
bitset<1005> f[1005];
void solve()
{
memset(f, 0, sizeof(f));
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; };
vector rec(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[get(dx + 1000, dy + 1000)].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 = -n + 1000; i <= n + 1000; ++i)
for(int j = -m + 1000; j <= m + 1000; ++j)
if(int cur = get(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: 0
Runtime Error
input:
4 2 5 .OO.. O..O. 1 3 O.O 1 3 .O. 2 3 OOO OOO