結果

問題 No.307 最近色塗る問題多くない?
ユーザー maine_honzukimaine_honzuki
提出日時 2021-05-14 21:16:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,721 bytes
コンパイル時間 2,585 ms
コンパイル使用メモリ 209,824 KB
実行使用メモリ 13,752 KB
最終ジャッジ日時 2024-04-09 23:44:33
合計ジャッジ時間 8,722 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,752 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 402 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 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});
                    }
                }
            }
        }
        bool maine = false;
        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