QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#635695#7733. Cool, It’s Yesterday Four Times MoreAkoasm_XWA 1ms5884kbC++201.9kb2024-10-12 20:37:272024-10-12 20:37:28

Judging History

你现在查看的是最新测评结果

  • [2024-10-12 20:37:28]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5884kb
  • [2024-10-12 20:37:27]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
typedef long long LL;

inline int read(){
	int x = 0 , f = 1 ; char c = getchar() ;
    while( c < '0' || c > '9' ){if( c == '-' ) f = -1 ;c = getchar() ;} 
    while( c >= '0' && c <= '9' ) { x = x * 10 + c - '0' ; c = getchar() ; }
    return x * f ;
}

const int maxn = 1024;
int n,m;
int f[maxn][maxn],cnt[maxn];
char S[maxn][maxn];
bool vis[maxn][maxn];

int dx[] = {0,-1,0,1};
int dy[] = {1,0,-1,0};

int id(int x,int y){
	return (x - 1) * m + y;
}

bool in(int x,int y){
	return 1 <= x && x <= n && 1 <= y && y <= m;
}

void dfs(int x,int y,int i,int j){
	if(in(x,y)&&in(i,j)){
		if(vis[id(x,y)][id(i,j)]) return ;
		vis[id(x,y)][id(i,j)] = 1;
//		if(x==1&&y==4) cout<<i<<" "<<j<<endl;
		cnt[id(x,y)]++;
	}
	for(int c=0;c<4;c++){
		int xt = x + dx[c];
		int yt = y + dy[c];
		int it = i + dx[c];
		int jt = j + dy[c];
		if(in(xt,yt) && in(it,jt) && S[xt][yt]=='.'){
			dfs(xt,yt,it,jt);
		}
	}
}

void solve(){
	n = read();m = read();
	for(int i=1;i<=n;i++){
		scanf("%s",S[i]+1);
		for(int j=1;j<=m;j++) vis[i][j] = cnt[id(i,j)] = 0;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(S[i][j]!='.') continue;
			int t = id(i,j);
			for(int x=1;x<=n;x++){
				for(int y=1;y<=m;y++){
					if(S[x][y]=='.') continue;
					dfs(i,j,x,y);
					//cnt[id(i,j)]++;
				}
			}
			for(int x=1;x<=n;x++){
				dfs(i,j,x,0);
				dfs(i,j,x,m+1);
			}
			for(int y=1;y<=m;y++){
				dfs(i,j,0,y);
				dfs(i,j,n+1,y);
			}
		}
	}
	int Ans = 0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			if(S[i][j]=='0') continue;
//			cout<<i<<" "<<j<<" "<<cnt[id(i,j)]<<endl;
			Ans += cnt[id(i,j)]==(n*m-1);
		}
	printf("%d\n",Ans);
}

int main(){
	int T = 1;T = read();
	while(T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5824kb

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: 5884kb

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
0
1
1
2
0
1
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
1
0
0
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
3
0
0
0
0
0
0
0
0
0
0
1
0
1
0
1
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
0
0
0
1
1
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
1
0
0
0
0
0
0
0
1
0
0
1
0
0
0
0
1
0
0
0
0
0
2
1
0
...

result:

wrong answer 4th lines differ - expected: '2', found: '0'