이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |