結果

問題 No.307 最近色塗る問題多くない?
ユーザー iqueue02iqueue02
提出日時 2020-01-15 23:10:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,164 bytes
コンパイル時間 3,204 ms
コンパイル使用メモリ 174,288 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 16:38:05
合計ジャッジ時間 10,364 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 428 ms
4,376 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
int main(){
  int h, w;
  cin >> h >> w;
  vector<vector<int>> a(h, vector<int>(w));
  rep(i,h) rep(j,w) cin >> a[i][j];
  int q, cnt0 = 0, cnt1 = 0;
  cin >> q;
  int allc = -1;
  while (q--) {
    int r, c, x;
    cin >> r >> c >> x;
    r--; c--;
    if (cnt0 == h*w || cnt1 == h*w) {
      allc = x;
      continue;
    }
    if (a[r][c] == x) continue;

    queue<P> que;
    que.push(make_pair(r, c));
    while (!que.empty()) {
      auto p = que.front(); que.pop();
      if (a[p.first][p.second] == x) continue;
      a[p.first][p.second] = x;
      if (x == 0) cnt0++;
      else cnt1++;
      for (int i = 0; i < 4; i++) {
        int nx = p.first + dx[i], ny = p.second + dy[i];
        if (nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
        if (a[nx][ny] == x) continue;
        que.push(make_pair(nx,ny));
      }
    }
  }
  rep(i,h) {
    rep(j,w) cout << (allc != -1 ? allc : a[i][j]) << " ";
    cout << endl;
  }
  return 0;
}
0