This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |