結果

問題 No.307 最近色塗る問題多くない?
ユーザー maine_honzukimaine_honzuki
提出日時 2021-05-14 20:01:18
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,575 bytes
コンパイル時間 2,450 ms
コンパイル使用メモリ 209,604 KB
実行使用メモリ 10,528 KB
最終ジャッジ日時 2024-04-09 23:06:25
合計ジャッジ時間 8,496 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 368 ms
6,940 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 #

//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 cnt = 0, clr = -1;
    while (Q--) {
        int R, C, X;
        cin >> R >> C >> X;
        R--;
        C--;
        if (cnt > H + W + H * W) {
            clr = X;
            continue;
        }
        if (A[R][C] == X)
            continue;
        cnt++;
        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();
            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;
            }
        }
    }
    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