# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
345663 |
2021-01-07T19:40:27 Z |
pggp |
Paint (COI20_paint) |
C++14 |
|
0 ms |
0 KB |
#include <bits/stdc++.h>
using namespace std;
int R, S;
int parent[250000];
int siz[250000];
bool db = false;
int find(int x){
if(parent[x] == x){
return x;
}
return parent[x] = find(parent[x]);
}
void un(int x, int y){
parent[find(x)] = find(y);
}
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 color2(int v, int c){
dfs(v, c);
while(!us.empty()){
used[us.top()] = false;
us.pop();
}
}
vector < int > E[250000];
int col[250000];
bool active[250000];
void union_vertices(vector < int > X, int y){
if(!active[y]) return;
vector < int > X1;
set < int > x1S;
for(int x : X){
if(active[x]){
X1.push_back(x);
x1S.insert(x);
un(x, y);
active[x] = false;
}
}
//cout << "UNION " << x << " " << y << endl;
set < int > S;
vector < int > v;
vector < int > v1;
for(int ver : E[y]){
if(x1S.find(ver) == x1S.end() and active[ver]){
S.insert(ver);
v.push_back(ver);
}
}
for(int x : X1){
for(int ver : E[x]){
if(S.find(ver) == S.end() and active[ver]){
S.insert(ver);
v1.push_back(ver);
}
}
}
E[y].clear();
for(int ver : v){
//cout << "ver = " << ver << endl;
E[y].push_back(ver);
}
for(int ver : v1){
if(ver == y) continue;
//cout << "ver = " << ver << endl;
E[y].push_back(ver);
E[ver].push_back(y);
}
}
bool used[250000];
stack < int > us;
void color(int v, int c){
//cout << v << ":" << c << endl;
col[v] = c;
vector < int > t = E[v];
vector < int > to_activ;
for(int ver : t){
if(col[ver] == c){
to_activ.push_back(ver);
}
}
union_vertices(to_activ, v);
}
void print_output(){
for (int y = 0; y < R; ++y)
{
for (int x = 0; x < S; ++x)
{
cout << col[find(y * S + x)] << " ";
if(db) cout << "(" << find(y * S + x) << ")";
}
cout << endl;
}
if(db)
{
for(int i = 0; i < R * S; i++){
cout << i << ": ";
for(int v : E[i]){
cout << v << " ";
}
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)
{
active[i] = true;
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)
{
cout << y * S + x << endl;
int c;
cin >> c;
color(find(y * S + x), c);
//print_output();
//cout << endl << endl;
}
}
int q;
cin >> q;
while(q--){
cout << q << endl;
int r, s, c;
cin >> r >> s >> c;
r--;
s--;
if(db) print_output();
if(db) cout << endl << endl;
color(find(r * S + s), c);
//print_output();
//cout << endl << endl;
}
print_output();
}
Compilation message
paint.cpp: In function 'void dfs(int, int)':
paint.cpp:29:11: error: 'col' was not declared in this scope; did you mean 'cosl'?
29 | int c1 = col[v];
| ^~~
| cosl
paint.cpp:30:16: error: 'E' was not declared in this scope
30 | for(int ver : E[v]){
| ^
paint.cpp:29:6: warning: unused variable 'c1' [-Wunused-variable]
29 | int c1 = col[v];
| ^~
paint.cpp: At global scope:
paint.cpp:96:6: error: redefinition of 'bool used [250000]'
96 | bool used[250000];
| ^~~~
paint.cpp:23:6: note: 'bool used [250000]' previously declared here
23 | bool used[250000];
| ^~~~
paint.cpp:97:15: error: redefinition of 'std::stack<int> us'
97 | stack < int > us;
| ^~
paint.cpp:24:15: note: 'std::stack<int> us' previously declared here
24 | stack < int > us;
| ^~