Submission #393099

# Submission time Handle Problem Language Result Execution time Memory
393099 2021-04-22T17:43:34 Z Blistering_Barnacles Paint (COI20_paint) C++11
0 / 100
68 ms 23924 KB
//apig's property
//Happiness can be found, even in the darkest of times, if one only remembers to turn on the light
//El Pueblo Unido Jamas Sera Vencido
//The saddest thing about betrayal? is that it never comes from your enemies
//Do or do not... there is no try
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define F first
#define S second
#define pb push_back
#define vll vector< ll >
#define vi vector< int >
#define pll pair< ll , ll >
#define pi pair< int , int >
#define all(s) s.begin() , s.end()
#define sz(s) s.size()
#define str string
#define md ((s + e) / 2)
#define mid ((l + r) / 2)
#define msdp(dp) memset(dp , -1 , sizeof dp)
#define mscl(dp) memset(dp , 0 , sizeof dp)
#define C continue
#define R return
#define B break
#define lx node * 2
#define rx node * 2 + 1
using namespace std;
typedef long long ll;
ll q, par[500005] , b[555555], k, l, m, n, o, p;
map < char , ll > mp;
vll adj[555555];
const ll mod = 1e9+7;
str s;
ll getpar(ll x){
    if(x == par[x])R x ;
    else R par[x] = getpar(par[x]) ;
}
ll vis[555555] ;
void mrg(ll x , ll y){
    x = getpar(x) , y = getpar(y) ;
    if(x == y)R ;
    par[y] = x ;
}
void dfs(ll v , ll pr , ll op){
    mrg(op , v) ;
    vis[v]++ ;
    for(auto u : adj[v]){
        if(u == pr || vis[u])C ;
        dfs(u , v , op) ;
    }
}
pll arr[555555] ;
void solve(){
    cin >> n >> m;
    const ll N = n , M = m;
    ll a[N + 5][M + 5] ;
    for(ll i = 1 ; i <= n; i++){
        a[i][m + 1] = a[i][0] = -1 ;
        for(ll j = 1 ; j <= m ; j++){
            a[n + 1][j] = a[0][j] = -1;
            cin >> a[i][j] ;
            arr[(i - 1) * m + j] = {i , j} ;
        }
    }
    for(ll i = 1 ; i <= n * m ; i++)par[i] = i ;
    for(ll i = 1 ; i <= n ; i++){
        for(ll j = 1 ; j <= m ; j++){
            ll op = (i - 1) * m + j ;
            if(a[i][j] == a[i][j + 1])adj[op].pb((i - 1) * m + j + 1) ;
            if(a[i][j] == a[i][j - 1])adj[op].pb((i - 1) * m + j - 1) ;
            if(a[i][j] == a[i + 1][j])adj[op].pb((i) * m + j) ;
            if(a[i][j] == a[i - 1][j])adj[op].pb((i - 2) * m + j) ;
        }
    }
    for(ll i = 1 ; i <= n * m ; i++){
        if(!vis[i]){
            b[i] = a[arr[i].F][arr[i].S] ;
            dfs(i , 0 , i) ;
        }
    }
    cin >> k;
    while(k--){
        cin >> o >> p >> l ;
        ll op = getpar((o - 1) * m + p) ;
        b[op] = l ;
    }
    for(ll i = 1 ; i <= n *  m ; i++){
        cout << b[getpar(i)] << " " << (i % m == 0 ? "\n" : "") ;
    }
}
int main(){
    fast ;
    //cin >> q;
    q = 1;
    while(q--){
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 13388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 17960 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 68 ms 23924 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 64 ms 22980 KB Output isn't correct
2 Halted 0 ms 0 KB -