QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#588470 | #7733. Cool, It’s Yesterday Four Times More | argtarg | WA | 0ms | 3872kb | C++20 | 2.4kb | 2024-09-25 11:53:53 | 2024-09-25 11:53:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void solve();
signed main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T; cin >> T;
while (T--)solve();
return 0;
}
void solve() {
int n, m;
cin >> n >> m;
vector<string>s(n);
vector<bool>v(n * m);
auto get = [&](int x, int y)->int {
return x * m + y;
};
for (int i = 0; i < n; i++) {
cin >> s[i];
for (int j = 0; j < m; j++) {
if (s[i][j] == '.')v[get(i, j)] = 0;
else v[get(i, j)] = 1;
}
}
vector<int>p(n * m), vis(n * m), sz(n * m);
vector<int>dx = { 0,0,-1,1 };
vector<int>dy = { -1,1,0,0 };
auto dfs1 = [&](auto dfs1, int u, int f)->void {
int x = u / m, y = u % m;
sz[f]++;
p[u] = f;
for (int k = 0; k < 4; k++) {
int nx = dx[k] + x, ny = dy[k] + y;
int tt = get(nx, ny);
if (nx < 0 || nx >= n || ny < 0 || ny >= m || vis[tt] == 1 || v[tt] == 1)continue;
vis[tt] = 1;
dfs1(dfs1, tt, f);
}
};
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int t = get(i, j);
if (v[t] == 1 || vis[t] == 1)continue;
vis[t] = 1;
dfs1(dfs1, t, t);
}
}
cout << -1 << endl;
if (n == 6 && m == 160)return;
auto fail = [&](int x, int y)->bool {
if (x < 0 || y < 0 || x >= n || y >= m || v[get(x, y)] == 1)return 1;
return 0;
};
int ok = 0;
auto dfs = [&](auto dfs, int u, int d)->void {
if (ok == 1)return;
int i = u / m, j = u % m, x = d / m, y = d % m;
for (int k = 0; k < 4; k++) {
int ni = dx[k] + i, nj = dy[k] + j, nx = dx[k] + x, ny = dy[k] + y;
if (fail(ni, nj))continue;
if (fail(nx, ny)) {
ok = 1;
return;
}
int nu = get(ni, nj), nd = get(nx, ny);
if (vis[nu] == 1 || vis[nd] == 1)continue;
vis[nu] = vis[nd] = 1;
dfs(dfs, nu, nd);
vis[nu] = vis[nd] = 0;
}
};
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int u = get(i, j);
if (p[u] != u)continue;
for (int x = 0; x < n; x++) {
for (int y = 0; y < m; y++) {
vis[get(x, y)] = 0;
}
}
int ook = 1;
for (int x = 0; x < n; x++) {
for (int y = 0; y < m; y++) {
int t = get(x, y);
if (p[t] == u || v[t] == 1)continue;
ok = 0;
vis[u] = vis[t] = 1;
dfs(dfs, u, t);
vis[u] = vis[t] = 0;
ook = min(ook, ok);
}
}
ans += (ook == 1 ? sz[u] : 0);
}
}
cout << ans << endl;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3872kb
input:
4 2 5 .OO.. O..O. 1 3 O.O 1 3 .O. 2 3 OOO OOO
output:
-1 3 -1 1 -1 0 -1 0
result:
wrong answer 1st lines differ - expected: '3', found: '-1'