QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#586297 | #7733. Cool, It’s Yesterday Four Times More | limpid | WA | 1ms | 3932kb | C++14 | 2.5kb | 2024-09-24 10:34:31 | 2024-09-24 10:34:31 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
using namespace std;
inline int read(){
int f=1,ans=0; char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
return f*ans;
}
const int MAXN = 1e3 + 11;
int cas, N, M;
int Q(int x, int y){return (x - 1) * M + y;}
struct Union{
int f[MAXN];
void Init(){for(int i = 1; i <= N * M; i++) f[i] = i; return;}
int find(int x){return f[x] == x ? x : f[x] = find(f[x]);}
void merge(int x, int y){f[find(y)] = f[find(x)]; return;}
}U;
char str[MAXN][MAXN];
vector<pii> vec[MAXN];
int sta[MAXN], Ans;
bool vis[MAXN][MAXN];
int main(){
//freopen("1.in", "r", stdin);
cas = read();
while(cas--){
N = read(), M = read(); U.Init();
int tot = 0;
for(int i = 1; i <= N * M; i++) vec[i].clear();
for(int i = 1; i <= N; i++){
scanf("%s", str[i] + 1);
}
for(int i = 1; i <= N; i++){
for(int j = 1; j <= M; j++){
if(j > 1 && str[i][j] == '.' && str[i][j - 1] == '.') U.merge(Q(i, j), Q(i, j - 1));
if(i > 1 && str[i][j] == '.' && str[i - 1][j] == '.') U.merge(Q(i, j), Q(i - 1, j));
}
}/*
for(int i = 1; i <= N; i++){
for(int j = 1; j <= M; j++) cerr << U.find(Q(i, j)) << " "; cerr << endl;
}*/
for(int i = 1; i <= N; i++) for(int j = 1; j <= M; j++) if(str[i][j] == '.') vec[U.find(Q(i, j))].pb(mp(i, j));
Ans = sta[0] = 0;
for(int i = 1; i <= N; i++) for(int j = 1; j <= M; j++) if(U.find(Q(i, j)) == Q(i, j) && str[i][j] == '.') sta[++sta[0]] = Q(i, j);
for(int i = 1; i <= sta[0]; i++){
bool flag = 0;//flag = 1
for(auto k: vec[sta[i]]){
for(auto tp: vec[sta[i]]) vis[tp.fi - k.fi + N][tp.se - k.se + M] = 1;
for(int j = 1; j <= sta[0]; j++){
if(i == j) continue;
bool g = 1; int cc = 0;
for(auto tp: vec[sta[j]]){
if(vis[tp.fi - vec[sta[j]][0].fi + N][tp.se - vec[sta[j]][0].se + M]){
cc++;
}
}if(cc == vec[sta[i]].size()){
flag = 1;
break;
}
}
for(auto tp: vec[sta[i]]) vis[tp.fi - k.fi + N][tp.se - k.se + M] = 0;
if(flag) break;
}
//cerr<<"i:"<<i<<" siz:"<< vec[sta[i]].size()<<" "<<flag<<" sta:"<< sta[i] <<endl;
//return 0;
if(!flag) Ans += vec[sta[i]].size();
}
printf("%d\n", Ans);
}return 0;
}/*
4
2 5
.OO..
O..O.
1 3
O.O
1 3
.O.
2 3
OOO
OOO
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3804kb
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
Wrong Answer
time: 1ms
memory: 3932kb
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. ...
output:
3 0 0 2 1 1 5 0 0 1 0 7 9 4 4 0 6 5 2 0 1 6 4 5 2 0 0 5 3 3 1 4 1 0 7 5 2 3 9 3 0 6 2 2 2 0 4 6 6 3 5 2 5 5 2 1 0 3 3 4 4 2 2 0 7 6 4 8 5 3 2 5 2 1 2 1 4 0 0 2 5 1 4 6 9 1 6 2 2 5 4 5 2 1 0 1 9 3 4 11 0 3 2 1 0 0 4 3 1 4 3 10 3 0 3 6 2 5 1 3 3 4 0 2 11 2 2 4 0 4 4 6 2 1 2 3 0 5 0 16 4 3 2 6 0 8 3 3 ...
result:
wrong answer 7th lines differ - expected: '3', found: '5'