結果

問題 No.307 最近色塗る問題多くない?
ユーザー simansiman
提出日時 2023-06-08 01:59:52
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 149 ms / 4,000 ms
コード長 1,444 bytes
コンパイル時間 1,259 ms
コンパイル使用メモリ 105,568 KB
実行使用メモリ 7,012 KB
最終ジャッジ日時 2023-08-28 20:22:02
合計ジャッジ時間 4,085 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 8 ms
4,376 KB
testcase_08 AC 28 ms
6,500 KB
testcase_09 AC 11 ms
5,320 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 11 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 25 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 12 ms
5,176 KB
testcase_18 AC 28 ms
6,132 KB
testcase_19 AC 27 ms
6,088 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 23 ms
5,488 KB
testcase_22 AC 22 ms
6,628 KB
testcase_23 AC 112 ms
6,804 KB
testcase_24 AC 45 ms
5,544 KB
testcase_25 AC 86 ms
6,744 KB
testcase_26 AC 148 ms
6,888 KB
testcase_27 AC 23 ms
4,380 KB
testcase_28 AC 39 ms
6,980 KB
testcase_29 AC 17 ms
4,380 KB
testcase_30 AC 149 ms
7,012 KB
testcase_31 AC 39 ms
4,376 KB
testcase_32 AC 39 ms
4,376 KB
testcase_33 AC 15 ms
6,900 KB
testcase_34 AC 38 ms
4,376 KB
testcase_35 AC 40 ms
5,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int g_visited[210][210];
int g_vid;
int A[210][210];

const int DY[4] = {-1, 0, 1, 0};
const int DX[4] = {0, 1, 0, -1};

int fill_x(int y, int x, int c, int nc) {
  int cnt = 1;
  g_visited[y][x] = g_vid;
  A[y][x] = nc;

  for (int dir = 0; dir < 4; ++dir) {
    int ny = y + DY[dir];
    int nx = x + DX[dir];
    if (A[ny][nx] != c) continue;

    cnt += fill_x(ny, nx, c, nc);
  }

  return cnt;
}

int main() {
  g_vid = 0;
  memset(g_visited, -1, sizeof(g_visited));

  int H, W;
  cin >> H >> W;
  memset(A, -1, sizeof(A));

  for (int y = 1; y <= H; ++y) {
    for (int x = 1; x <= W; ++x) {
      cin >> A[y][x];
    }
  }
  int Q;
  cin >> Q;
  int max_cnt = 0;
  int last_color = -1;

  for (int i = 0; i < Q; ++i) {
    int R, C, X;
    cin >> R >> C >> X;

    if (max_cnt == H * W) {
      last_color = X;
      continue;
    }

    if (A[R][C] == X) continue;
    int cnt = fill_x(R, C, A[R][C], X);
    max_cnt = max(max_cnt, cnt);
  }

  for (int y = 1; y <= H; ++y) {
    for (int x = 1; x <= W; ++x) {
      if (last_color != -1) {
        cout << last_color;
      } else {
        cout << A[y][x];
      }
      if (x < W) cout << " ";
    }
    cout << endl;
  }

  return 0;
}
0