Submission #704782

# Submission time Handle Problem Language Result Execution time Memory
704782 2023-03-03T02:29:06 Z chenyan Zoo (COCI19_zoo) C++17
0 / 110
1 ms 340 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb emplace_back
#define N 2010
char c[N][N];
int boss[N*N];
int find(int x){
	return boss[x]?boss[x]=find(boss[x]):x;
}
void Union(int u,int v){
	u=find(u),v=find(v);
	if(u==v)return;
	boss[u]=v;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m,i,j;
	cin>>n>>m;
	for(i=1;i<=n;i++)for(j=1;j<=m;j++)
		cin>>c[i][j];
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			if(c[i][j]=='*')continue;
			if(c[i][j+1]==c[i][j])Union(i*N+j,i*N+j+1);
			if(c[i+1][j]==c[i][j])Union((i+1)*N+j,i*N+j);
		}
	}
	int ans=0;
	assert(c[1][1]==c[n][m]);
	for(i=1;i<=n;i++)for(j=1;j<=m;j++)
		if(c[i][j]!='*'&&boss[i*N+j]==0)ans++;
	cout<<ans<<'\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -