# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
559273 |
2022-05-09T14:53:58 Z |
Redhood |
Paint (COI20_paint) |
C++14 |
|
122 ms |
16620 KB |
#include<bits/stdc++.h>
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define pb push_back
#define mkp make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
vector < vector < int > > g;
const int N = (int)2e5 + 10;
vector < int > st[N];
int p[N], cur_color[N];
void make(int v, int C){
p[v] = v;
cur_color[v] = C;
}
int fin(int v){
if(p[v] == v)return v;
return p[v] = fin(p[v]);
}
void un(int a , int b){
a = fin(a) , b = fin(b);
if(a == b)
return;
if(sz(st[a]) < sz(st[b]))
swap(a , b);
p[b] = a;
for(auto &u : st[b]){
if(fin(u) != a)
st[a].pb(u);
}
}
vector < pair < int , int > > dir = {{-1,0},{+1,0},{0,-1},{0,+1}};
int r , s;
bool valid(int x , int y){
if(x >= 0 && x < r && y >= 0 && y < s)
return true;
return false;
}
bool onezero = 1;
void makeit(int cell, int clr){
cell = fin(cell);
if(cur_color[cell] == clr)
return;
vector < int > unite_with;
for(auto &u : st[cell]){
if(fin(u) != cell && cur_color[fin(u)] == clr){
unite_with.pb(u);
}
}
st[cell].clear();
for(auto &u : unite_with)
un(u , cell);
cur_color[fin(cell)] = clr;
}
signed main(){
ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
cin >> r >> s;
g.resize(r , vector < int > (s));
onezero = 1;
for(int i = 0; i < r; ++i)
for(int j = 0; j < s; ++j){
cin >> g[i][j];
if(g[i][j] > 1)
onezero = 0;
}
for(int i = 0; i < r * s; ++i)
make(i, g[i / s][i % s]);
for(int i = 0; i < r; ++i)
for(int j = 0; j < s; ++j){
for(auto &u : dir){
int i1 = i + u.fi , j1 = j + u.se;
if(valid(i1, j1)){
if(g[i1][j1] == g[i][j])
un(i1*s + j1, i*s + j);
}
}
}
for(int i = 0; i < r; ++i)
for(int j = 0; j < s; ++j){
for(auto &u : dir){
int i1 = i + u.fi , j1 = j + u.se;
if(valid(i1, j1)){
if(g[i1][j1] != g[i][j]){
st[fin(i*s+j)].pb(fin(i1*s+j1));
}
}
}
}
int q;
cin >> q;
for(int i = 0; i < q; ++i){
/// online lol
int x , y, c;
cin >> x >> y >> c;
--x,--y;
makeit(x * s + y, c);
if(c > 1){
onezero = 0;
}
}
for(int i = 0; i < r; ++i){
for(int j = 0; j < s; ++j){
cout << cur_color[fin(i * s + j)] << ' ';
}
cout << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
3 ms |
5020 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
7012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
16368 KB |
Output is correct |
2 |
Correct |
104 ms |
16028 KB |
Output is correct |
3 |
Correct |
106 ms |
16620 KB |
Output is correct |
4 |
Correct |
122 ms |
16388 KB |
Output is correct |
5 |
Correct |
99 ms |
15372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
91 ms |
11208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |