답안 #1003908

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003908 2024-06-20T19:49:41 Z vjudge1 Paint (COI20_paint) C++14
0 / 100
131 ms 49232 KB
#include <bits/stdc++.h>
using namespace std;

#define bug(x) cout << #x << " " << x << endl

const int maxn = 2e5 + 10;

vector<int> pai( maxn ), cor( maxn );
set<int> edges[maxn];

int id( int i, int j, int m ){ return (i - 1)*m + j; }

int find( int a ){ return (( a == pai[a] ) ? a : pai[a] = find(pai[a])); }
void join( int a, int b ){
  a = find(a); b = find(b);
  if( a == b ) return;
  if( edges[a].size() < edges[b].size() ) swap( a, b );
  pai[b] = a;
  for( int x : edges[b] ) edges[a].insert(x);
}


int main(){
  int n, m; cin >> n >> m;
  for( int i = 1; i <= n; i++ ){
    for( int j = 1; j <= m; j++ ){
      cin >> cor[id(i, j, m)];
      pai[id(i, j, m)] = id(i,j, m);
      if( i > 1 ){
        if( cor[id(i, j, m)] == cor[id(i - 1, j, m )] ){
          join( id(i, j, m), id(i - 1, j, m ) );
        }
        else{
          edges[id(i, j, m)].insert(id(i - 1, j, m ));
          edges[id(i - 1, j, m)].insert(id(i, j, m));
        }
      }

      if( j > 1 ){
        if( cor[id(i, j, m)] == cor[id(i, j - 1, m )] ){
          join( id(i, j, m), id(i, j - 1, m ) );
        }
        else{
          edges[id(i, j, m)].insert(id(i, j - 1, m ));
          edges[id(i, j - 1, m)].insert(id(i, j, m));
        }
      }
    }
  }

  int q; cin >> q;
  queue<int> aux;
  while( q-- ){
    int i, j, c; cin >> i >> j >> c;
    int rep = find(id(i, j, m));
    cor[rep] = c;
    for( auto it = edges[rep].begin(); it != edges[rep].end(); ){
      if( find(*it) == rep || cor[find(*it)] == cor[rep] ){
        aux.push(*it);
        it = edges[rep].erase(it);
      }
      else it++;
    }
    while( !aux.empty() ){ join( rep, aux.front() ); aux.pop(); rep = find(rep); }
  }

  for( int i = 1; i <= n; i++ ){
    for( int j = 1; j <= m; j++ ) cout << cor[find(id(i, j, m))] << " ";
    cout << endl;
  }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 11356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 15628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 131 ms 49232 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 99 ms 38476 KB Output isn't correct
2 Halted 0 ms 0 KB -