結果

問題 No.307 最近色塗る問題多くない?
ユーザー iqueue02iqueue02
提出日時 2020-01-15 23:19:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 209 ms / 4,000 ms
コード長 1,169 bytes
コンパイル時間 1,821 ms
コンパイル使用メモリ 173,536 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 17:30:57
合計ジャッジ時間 4,421 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 25 ms
4,380 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 20 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 12 ms
4,384 KB
testcase_18 AC 35 ms
4,380 KB
testcase_19 AC 32 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 24 ms
4,376 KB
testcase_22 AC 22 ms
4,376 KB
testcase_23 AC 176 ms
4,380 KB
testcase_24 AC 68 ms
4,380 KB
testcase_25 AC 110 ms
4,376 KB
testcase_26 AC 209 ms
4,380 KB
testcase_27 AC 21 ms
4,380 KB
testcase_28 AC 32 ms
4,376 KB
testcase_29 AC 14 ms
4,380 KB
testcase_30 AC 206 ms
4,380 KB
testcase_31 AC 33 ms
4,380 KB
testcase_32 AC 31 ms
4,376 KB
testcase_33 AC 9 ms
4,380 KB
testcase_34 AC 31 ms
4,380 KB
testcase_35 AC 33 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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));
  int cnt = 0;
  rep(i,h) rep(j,w) cin >> a[i][j], cnt += a[i][j];
  int q;
  cin >> q;
  int allc = -1;
  while (q--) {
    int r, c, x;
    cin >> r >> c >> x;
    r--; c--;
    if (cnt == h*w || cnt == 0) {
      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) cnt--;
      else cnt++;
      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