답안 #773908

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
773908 2023-07-05T09:28:20 Z vjudge1 Paint (COI20_paint) C++17
9 / 100
40 ms 7448 KB
#include<bits/stdc++.h>
using namespace std;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
//#define int long long int
#define N 200005
int limit[N][2],renk[N];
int father[N];
int dsu(int x){
	if(father[x]==x)return x;
	return father[x]=dsu(father[x]);
}
void kardes(int x,int y){
	x=dsu(x),y=dsu(y);
	if(x==y)return;
	father[y]=x;
	limit[x][0]=min(limit[x][0],limit[y][0]);

	limit[x][1]=max(limit[x][1],limit[y][1]);
}
int geldik[N];
int main(){
	lalala;
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=1;j<=m;j++){
			cin>>renk[j];
			limit[j][0]=limit[j][1]=j;
			father[j]=j;
		}
	}
	for(int i=1;i<=m;i++){
		if(geldik[i])continue;
		geldik[i]=1;
		for(int j=i-1;j>0;j--){
			if(renk[j]!=renk[i])break;

			geldik[j]=1;
			kardes(i,j);
		}
		for(int j=i+1;j<=m;j++){
			if(renk[j]!=renk[i])break;
			geldik[j]=1;
			kardes(i,j);
		}
	}
	int q;cin>>q;
	while(q--){
		int x_x,uwu,OwO;cin>>x_x>>uwu>>OwO;
		uwu=dsu(uwu);
		int alt=limit[uwu][0]-1, ust=limit[uwu][1]+1;
		renk[uwu]=OwO;
		if(alt>0&&renk[dsu(alt)]==OwO){
			kardes(uwu,dsu(alt));
		}
		if(ust<=m&&renk[dsu(ust)]==OwO){
			kardes(uwu,dsu(ust));
		}
	}
	for(int i=0;i<n;i++){
		for(int j=1;j<=m;j++){
			cout<<renk[dsu(j)]<<" ";
		}cout<<endl;
	}

	
	
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 2048 KB Output is correct
2 Correct 30 ms 3544 KB Output is correct
3 Correct 40 ms 7448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 1004 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 1244 KB Output isn't correct
2 Halted 0 ms 0 KB -