# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
773782 |
2023-07-05T08:28:48 Z |
vjudge1 |
Paint (COI20_paint) |
C++17 |
|
3000 ms |
22948 KB |
#include <bits/stdc++.h>
using namespace std;
#define sp " "
//#define endl "\n"
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define N 200005
int root[N], col[N], sz[N];
vector<int> edges[N];
int find(int node){
//cout<<"! "<<node<<sp<<root[node]<<endl;
if (root[node] == node) return node;
return root[node] = find(root[node]);
}
void uni(int a,int b){
a = find(a), b = find(b);
//cout<<a<<sp<<b<<endl;
if (a == b) return;
if (sz[a] < sz[b]) swap(a, b);
if (edges[a].size() < edges[b].size()) edges[a].swap(edges[b]);
root[b] = a;
sz[a] += sz[b];
for (auto i : edges[b]) if (find(i) != a) edges[a].pb(i);
}
void change_color(int node, int c){
node = find(node);
int prv = col[node];
if (prv == c) return;
vector<int> merge = edges[node];
for (auto i : merge) if (col[find(i)] == c) uni(i, node);
col[find(node)] = c;
}
int32_t main(){
//fileio();
fastio();
vector<pii> dir;
dir.pb({0, 1});
dir.pb({1, 0});
int cntr = 1;
int r, s;
cin>>r>>s;
int arr[r + 5][s + 5], ind[r + 5][s + 5];
memset(arr, -1, sizeof(arr));
memset(ind, 0, sizeof(ind));
for (int i = 1; i <= r; i++){
for (int j = 1; j <= s; j++)
{
cin>>arr[i][j];
root[cntr] = cntr;
sz[cntr] = 1;
col[cntr] = arr[i][j];
ind[i][j] = cntr;
cntr++;
//cout<<i<<sp<<j<<sp<<ind[i][j]<<endl;
}
}
for (int i = 1; i <= r; i++)
{
for (int j = 1; j <= s; j++){
for (auto k : dir){
int a = i + k.st, b = j + k.nd;
if (ind[a][b] == 0) continue;
if (arr[a][b] == arr[i][j]) uni(ind[a][b], ind[i][j]);
else {
int u = find(ind[i][j]), v = find(ind[a][b]);
edges[u].pb(v);
edges[v].pb(u);
}
}
}
}
int q;
cin>>q;
while(q--){
int r, c, x;
cin>>r>>c>>x;
change_color(ind[r][c], x);
}
for (int i = 1; i <= r; i++){
for(int j = 1; j <= s; j++)
cout<<col[find(ind[i][j])]<<sp;
cout<<endl;
}
//cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
5 ms |
5588 KB |
Output is correct |
4 |
Correct |
6 ms |
5588 KB |
Output is correct |
5 |
Correct |
64 ms |
5616 KB |
Output is correct |
6 |
Correct |
44 ms |
5688 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
9520 KB |
Output is correct |
2 |
Correct |
54 ms |
14772 KB |
Output is correct |
3 |
Execution timed out |
3079 ms |
22948 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
397 ms |
19820 KB |
Output is correct |
2 |
Correct |
118 ms |
18348 KB |
Output is correct |
3 |
Correct |
167 ms |
19016 KB |
Output is correct |
4 |
Correct |
360 ms |
19380 KB |
Output is correct |
5 |
Correct |
987 ms |
18764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
14608 KB |
Output is correct |
2 |
Execution timed out |
3093 ms |
16104 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |