# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
345640 |
2021-01-07T17:52:44 Z |
pggp |
Paint (COI20_paint) |
C++14 |
|
3000 ms |
24928 KB |
#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;
color(find(r * S + s), c);
}
print_output();
}
Compilation message
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 |
1 |
Incorrect |
5 ms |
6252 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3057 ms |
9732 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3033 ms |
24108 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3042 ms |
24928 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |