# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
345641 |
2021-01-07T17:59:28 Z |
pggp |
Paint (COI20_paint) |
C++14 |
|
3000 ms |
23940 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;
r--;
s--;
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 |
Correct |
4 ms |
6252 KB |
Output is correct |
2 |
Correct |
5 ms |
6252 KB |
Output is correct |
3 |
Correct |
8 ms |
6764 KB |
Output is correct |
4 |
Correct |
10 ms |
6636 KB |
Output is correct |
5 |
Correct |
453 ms |
7272 KB |
Output is correct |
6 |
Correct |
665 ms |
7532 KB |
Output is correct |
7 |
Correct |
4 ms |
6252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
8556 KB |
Output is correct |
2 |
Correct |
333 ms |
12908 KB |
Output is correct |
3 |
Execution timed out |
3072 ms |
23344 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3037 ms |
23940 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
195 ms |
14848 KB |
Output is correct |
2 |
Execution timed out |
3048 ms |
16576 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |