QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#270458 | #7733. Cool, It’s Yesterday Four Times More | March_April | RE | 0ms | 0kb | C++20 | 3.1kb | 2023-11-30 21:25:11 | 2023-11-30 21:25:11 |
answer
#include <bits/stdc++.h>
using namespace std;
struct Node
{
int ans[4];
};
void solve()
{
int n, m;
cin >> n >> m;
vector<string> g(n);
for(int i = 0;i < n; i ++) cin >> g[i];
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
vector<vector<int>> block(n, vector<int> (m));//每个格子属于哪个连通块
int cnt = 0;//连通块的数量
vector<int> idx(1010);
auto bfs = [&] (int x, int y, int id)
{
queue<pair<int, int>> q;
q.push({x, y});
block[x][y] = id;
while(q.size())
{
auto [ix, iy] = q.front();
q.pop();
idx[id] ++;
for(int i = 0;i < 4; i ++)
{
int a = dx[i] + ix, b = dy[i] + iy;
if(a < 0 || a >= n || b < 0 || b >= m)
continue;
if(block[a][b] || g[a][b] == 'O') continue;
q.push({a, b});
block[a][b] = id;
}
}
};
for(int i = 0;i < n; i ++)
for(int j = 0;j < m; j ++)
if(!block[i][j] && g[i][j] != 'O')
bfs(i, j, ++ cnt);
vector<pair<int, int>> S[cnt + 1];
for(int i = 0;i < n; i ++)
for(int j = 0;j < m; j ++)
S[block[i][j]].push_back({i, j});
// for(int i = 1;i <= cnt; i ++)
// {
// //clog << S[i].size() << '\n';
// for(auto [x, y] : S[i])
// clog << x << ' ' << y << ' ' << i << '\n';
// }
int ans = 0;
auto check = [&] (vector<pair<int, int>> A, vector<pair<int, int>> B, int ddx, int ddy)
{
vector<vector<int>> st(n + 1000, vector<int> (m + 1000));
for(auto [x, y] : B)
st[x + ddx + 1000][y + ddy + 1000] = true;
for(auto [x, y] : A)
if(st[x][y])
return false;
return B.size() >= A.size();
};
for(int i = 1;i <= cnt; i ++)
{
bool M = true;
for(int j = 1;j <= cnt; j ++)
{
if(S[j].size() < S[i].size() || i == j)
continue;
bool ok = true;
for(auto [x, y] : S[i])//这个和j的左上角对齐
{
for(auto [xx, yy] : S[j])
{
if(check(S[i], S[j], -x + xx, -y + yy))
{
ok = false;
break;
}
if(!ok)
break;
}
}
if(!ok)
{
M = false;
break;
}
}
if(M)
{
//clog << idx[i] << ' ' << i << '\n';
ans += idx[i];
}
}
cout << ans << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt;
cin >> tt;
while(tt --)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
4 2 5 .OO.. O..O. 1 3 O.O 1 3 .O. 2 3 OOO OOO