結果

問題 No.307 最近色塗る問題多くない?
ユーザー maine_honzukimaine_honzuki
提出日時 2021-05-14 21:23:14
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,454 ms / 4,000 ms
コード長 1,693 bytes
コンパイル時間 2,456 ms
コンパイル使用メモリ 208,668 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-09 23:46:11
合計ジャッジ時間 9,259 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 34 ms
6,940 KB
testcase_08 AC 319 ms
6,940 KB
testcase_09 AC 124 ms
6,940 KB
testcase_10 AC 15 ms
6,940 KB
testcase_11 AC 41 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 23 ms
6,940 KB
testcase_14 AC 3 ms
6,944 KB
testcase_15 AC 3 ms
6,944 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 14 ms
6,940 KB
testcase_18 AC 37 ms
6,940 KB
testcase_19 AC 36 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 36 ms
6,944 KB
testcase_22 AC 26 ms
6,940 KB
testcase_23 AC 189 ms
6,944 KB
testcase_24 AC 91 ms
6,944 KB
testcase_25 AC 284 ms
6,944 KB
testcase_26 AC 219 ms
6,940 KB
testcase_27 AC 1,423 ms
6,940 KB
testcase_28 AC 1,118 ms
6,940 KB
testcase_29 AC 16 ms
6,944 KB
testcase_30 AC 224 ms
6,940 KB
testcase_31 AC 1,454 ms
6,944 KB
testcase_32 AC 36 ms
6,944 KB
testcase_33 AC 12 ms
6,940 KB
testcase_34 AC 35 ms
6,940 KB
testcase_35 AC 37 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//https://ncode.syosetu.com/n4830bu/307/
#include <bits/stdc++.h>
using namespace std;

int main() {
    int H, W;
    cin >> H >> W;
    vector A(H, vector(W, 0));
    for (auto&& V : A) {
        for (auto&& a : V) {
            cin >> a;
        }
    }
    int Q;
    cin >> Q;
    int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
    int clr = -1;
    bool maine = false;
    vector cnt(H, vector(W, 0));
    while (Q--) {
        int R, C, X;
        cin >> R >> C >> X;
        R--;
        C--;
        if (maine) {
            clr = X;
            continue;
        }
        if (A[R][C] == X)
            continue;

        vector seen(H, vector(W, false));
        queue<pair<int, int>> que;
        que.push({R, C});
        seen[R][C] = true;
        while (!que.empty()) {
            auto [h, w] = que.front();
            cnt[h][w]++;
            que.pop();
            for (int i = 0; i < 4; i++) {
                int h_nxt = h + dx[i], w_nxt = w + dy[i];
                if (h_nxt >= 0 && h_nxt < H && w_nxt >= 0 && w_nxt < W) {
                    if (!seen[h_nxt][w_nxt] && A[h_nxt][w_nxt] != X) {
                        seen[h_nxt][w_nxt] = true;
                        que.push({h_nxt, w_nxt});
                    }
                }
            }
        }
        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                if (seen[h][w])
                    A[h][w] = X;
                if (cnt[h][w] > H + W)
                    maine = true;
            }
        }
    }
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            cout << (clr == -1 ? A[h][w] : clr) << " \n"[w == W - 1];
        }
    }
}
0