Submission #1003865

#TimeUsernameProblemLanguageResultExecution timeMemory
1003865vjudge1Paint (COI20_paint)C++14
8 / 100
3079 ms18516 KiB
#include <bits/stdc++.h>
using namespace std;
#define bug(x) cout << #x << " " << x << endl

vector<vector<int>> mat, marc;
int di[] = {0, 1, 0, -1};
int dj[] = {1, 0, -1, 0};

void dfs( int i, int j, int cor, int id ){
  marc[i][j] = id;
  for( int d = 0; d < 4; d++ ) if( mat[i][j] == mat[i + di[d]][j + dj[d]] && marc[i][j] != marc[i + di[d]][j + dj[d]] ) dfs( i + di[d], j + dj[d], cor, id );
  mat[i][j] = cor;
}

int main(){
  int n, m; cin >> n >> m;
  mat = marc = vector<vector<int>>( n + 2, vector<int>(m + 2, -1) );
  for( int i = 1; i <= n; i++ ) for( int j = 1; j<= m; j++ ) cin >> mat[i][j];
  int q; cin >> q;
  for( int x = 1; x <= q; x++ ){
    int i, j, c; cin >> i >> j >> c;
    dfs( i, j, c, x );
  }
  for( int i = 1; i <= n; i++ ){
    for( int j = 1; j<= m; j++ ) cout << mat[i][j] << " ";
    cout << endl;
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...