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;
#define pb push_back
#define pii pair<int,int>
#define ff first
#define ss second
const int maxn = 1e3+5;
vector<vector<int>> mtx, mark;
int dx[4] = {1,-1,0,0}, dy[4] = {0,0,1,-1};
int n,m;
bool valid(int x, int y){
return (x>0 && y>0 && x<=n && y<=m && !mark[x][y]);
}
void dfs(int x, int y, int cor){
// cout << x << " " << y << endl;
mark[x][y]=true;
for(int i=0; i<4; i++){
int vx = x+dx[i];
int vy = y+dy[i];
if(valid(vx,vy) && mtx[x][y]==mtx[vx][vy]) dfs(vx,vy,cor);
}
mtx[x][y]=cor;
}
int main(){
cin >> n >> m;
mtx.resize(n+5);
mark.resize(n+5);
for(int i=1; i<=n; i++) mtx[i].resize(m+5), mark[i].resize(m+5);
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
int x; cin >> x;
mtx[i][j]=x;
}
}
int q; cin >> q;
for(int i=1; i<=q; i++){
int x,y,c; cin >> x >> y >> c;
dfs(x,y,c);
for(int j=1; j<=n; j++){
for(int k=1; k<=m; k++) mark[i][j]=false;
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cout << mtx[i][j] << " ";
}
cout << '\n';
}
}
# | 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... |