Submission #1003903

#TimeUsernameProblemLanguageResultExecution timeMemory
1003903PagodePaivaPaint (COI20_paint)C++17
0 / 100
376 ms524288 KiB
#include<bits/stdc++.h>

using namespace std;

vector <vector <int>> v;
int r, s;
	
bool check(int a, int b){
	return (a >= 0 and a < r and b >= 0 and b < s);
}
void dfs(int a, int b, int cor1, int cor2){
	if(v[a][b] == cor1) v[a][b] = cor2;
	else return;
	if(check(a-1, b)) dfs(a-1, b, cor1, cor2);
	if(check(a+1, b)) dfs(a+1, b, cor1, cor2);
	if(check(a, b-1)) dfs(a, b-1, cor1, cor2);
	if(check(a, b+1)) dfs(a, b+1, cor1, cor2);
	return;
}

int main(){
	cin >> r >> s;
	for(int i = 0;i < r;i++){
		vector <int> aux;
		for(int i = 0;i < s;i++){
			int x;
			cin >> x;
			aux.push_back(x);
		}
		v.push_back(aux);
	}
	int q;
	cin >> q;
	while(q--){
		int l, r, cor;
		cin >> l >> r >> cor;
		l--;
		r--;
		dfs(l, r, v[l][r], cor);
	}
	for(auto x : v){
		for(auto y : x){
			cout << y << ' ';
		}
		cout << endl;
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...