Submission #704784

# Submission time Handle Problem Language Result Execution time Memory
704784 2023-03-03T02:40:50 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 a=0,b=0;
	for(i=1;i<=n;i++)for(j=1;j<=m;j++){
		if(c[i][j]=='B'&&boss[i*N+j]==0)a++;
		if(c[i][j]=='T'&&boss[i*N+j]==0)b++;
	}
	if(a+b<4){
		cout<<a+b<<'\n';
	}
	else cout<<min(a,b)-1<<'\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 -