이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int R, S;
int cells[250000];
int parent[250000];
int find(int x){
return parent[x];
}
void un(int x, int y){
for (int i = 0; i < R * S; ++i)
{
if(parent[cells[i]] == parent[x]){
parent[cells[i]] = parent[y];
}
}
}
vector < int > E[250000];
int col[250000];
bool used[250000];
stack < int > us;
void dfs(int v, int c){
used[v] = true;
us.push(v);
int c1 = col[v];
for(int ver : E[v]){
if(!used[ver] and col[ver] == col[v]){
dfs(ver, c);
}
}
col[v] = c;
}
void color(int v, int c){
dfs(v, c);
while(!us.empty()){
used[us.top()] = false;
us.pop();
}
}
void print_output(){
for (int y = 0; y < R; ++y)
{
for (int x = 0; x < S; ++x)
{
cout << col[find(y * S + x)] << " ";
}
cout << endl;
}
}
int main(){
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
cin >> R >> S;
for (int i = 0; i < R * S; ++i)
{
col[i] = 100001 + i;
parent[i] = i;
if(i % S != S - 1){
E[i].push_back(i + 1);
}
if(i % S != 0){
E[i].push_back(i - 1);
}
if(i >= S){
E[i].push_back(i - S);
}
if(i < R*S - S){
E[i].push_back(i + S);
}
}
for (int y = 0; y < R; ++y)
{
for (int x = 0; x < S; ++x)
{
int c;
cin >> c;
color(find(y * S + x), c);
//print_output();
}
}
int q;
cin >> q;
while(q--){
int r, s, c;
cin >> r >> s >> c;
r--;
s--;
color(find(r * S + s), c);
}
print_output();
}
컴파일 시 표준 에러 (stderr) 메시지
paint.cpp: In function 'void dfs(int, int)':
paint.cpp:33:6: warning: unused variable 'c1' [-Wunused-variable]
33 | int c1 = col[v];
| ^~
# | 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... |