Submission #559254

#TimeUsernameProblemLanguageResultExecution timeMemory
559254RedhoodPaint (COI20_paint)C++14
0 / 100
3091 ms27184 KiB
#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); for(auto &u : st[cell]){ int t = cur_color[fin(u)]; if(t == clr){ un(cell , fin(u)); } } 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...