Submission #863447

# Submission time Handle Problem Language Result Execution time Memory
863447 2023-10-20T11:29:54 Z Rifal Paint (COI20_paint) C++14
0 / 100
14 ms 3420 KB
#include <bits/stdc++.h>
#include <fstream>
#define endl '\n'
#define mod 1000000007
#define INF 900000000
//#define cin fin
//#define cout fout
//#define fi first
//#define se second
using namespace std;
//ofstream fout("intel.out");
//ifstream fin("intel.in");

const int Max = 2e5 + 5;
pair<int,pair<int,int>> p[Max];
int ran[Max];
int col[Max];
void un(int a, int b) {
    if(ran[a] < ran[b]) {
        p[b].second.first = p[a].second.first;
        swap(a,b);
    }
    else {
        p[a].second.second = p[b].second.second;
    }
    if(ran[a] == ran[b]) ran[a]++;
    p[b].first = a;
     
}
int fin(int x) {
    if(p[x].first == x) return x;
    else return p[x].first = fin(p[x].first);
}
int main()
{
    ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    int r, s; cin >> r >> s; char arr[r][s+1];
    for(int i = 1; i <= s; i++) {
        p[i].first = i;
    }
    for(int i = 0; i < r; i++) {
        for(int j = 1; j <= s; j++) {
            cin >> arr[i][j];
        }
    }
    for(int i = 2; i <= s; i++) {
        int a = fin(i-1), b = fin(i);
        col[a] = arr[0][i-1]-'0';
        col[b] = arr[0][i]-'0';
        if(arr[0][i-1] != arr[0][i]) {
            p[a].second.second = b;
            p[b].second.first = a;
        }
    }
 
    for(int i = 2; i <= s; i++) {
        int a = fin(i-1), b = fin(i);
        if(arr[0][i-1] == arr[0][i]) {
            un(a,b);
        }
    }
    int q; cin >> q;
    while(q--) {
        int a, b, c; cin >> a >> b >> c; int z = fin(b);
        col[z] = c;
        
        if(p[z].second.first != 0 && col[p[z].second.first] == c) {
            un(fin(p[z].second.first),z);
        }
        if(p[z].second.second != 0 && col[p[z].second.second] == c) {
            un(z,fin(p[z].second.second));
        }
    }
    for(int i = 0; i < r; i++) {
        for(int j = 1; j <= s; j++) {
            cout << col[fin(j)] << ' ';
        }
        cout << endl;
    }
 return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 3004 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -