이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int MAXN=10010;
vector <int> v[MAXN],mark[MAXN];
int r, s;
void dfs(int x, int y, int cor){
mark[x][y] = 1;
if(x+1<=s && v[x+1][y]==v[x][y] && mark[x+1][y]==0) dfs(x+1, y, cor);
if(x-1>0 && v[x-1][y]==v[x][y] && mark[x-1][y]==0) dfs(x-1, y, cor);
if(y+1<=r && v[x][y+1]==v[x][y] && mark[x][y+1]==0) dfs(x, y+1, cor);
if(y-1>0 && v[x][y-1]==v[x][y] && mark[x][y-1]==0) dfs(x, y-1, cor);
v[x][y] = cor;
}
int main(){
cin >> r >> s;
for(int i=1; i<=r; i++){
v[i].push_back(0);
for(int j=1; j<=s; j++){
int x;
cin >> x;
v[i].push_back(x);
}
}
/*
for(int i=1; i<=r; i++){
for(int j=1; j<=s; j++) cout << v[i][j] << " ";
cout << endl;
}
*/
int q;
cin >> q;
for(int i=1; i<=r; i++){
for(int j=0; j<=s; j++){
mark[i].push_back(0);
}
}
for(int i=0; i<q; i++){
int x, y, cor;
cin >> x >> y >> cor;
for(int j=1; j<=r; j++){
for(int k=1; k<=s; k++){
mark[j][k] = 0;
}
}
dfs(x, y, cor);
}
for(int i=1; i<=r; i++){
for(int j=1; j<=s; j++){
cout << v[i][j] << " ";
}
cout << endl;
}
}
# | 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... |