結果

問題 No.307 最近色塗る問題多くない?
ユーザー H3PO4H3PO4
提出日時 2022-08-21 09:22:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 798 ms / 4,000 ms
コード長 1,012 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 83,072 KB
最終ジャッジ日時 2024-04-18 08:59:19
合計ジャッジ時間 7,071 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,272 KB
testcase_01 AC 42 ms
54,016 KB
testcase_02 AC 42 ms
54,016 KB
testcase_03 AC 41 ms
54,272 KB
testcase_04 AC 59 ms
67,200 KB
testcase_05 AC 48 ms
60,800 KB
testcase_06 AC 50 ms
61,824 KB
testcase_07 AC 85 ms
76,804 KB
testcase_08 AC 116 ms
77,056 KB
testcase_09 AC 85 ms
76,980 KB
testcase_10 AC 72 ms
74,368 KB
testcase_11 AC 79 ms
77,232 KB
testcase_12 AC 42 ms
54,144 KB
testcase_13 AC 67 ms
76,544 KB
testcase_14 AC 61 ms
69,248 KB
testcase_15 AC 70 ms
70,656 KB
testcase_16 AC 64 ms
70,400 KB
testcase_17 AC 102 ms
77,056 KB
testcase_18 AC 175 ms
77,272 KB
testcase_19 AC 159 ms
77,700 KB
testcase_20 AC 57 ms
65,920 KB
testcase_21 AC 142 ms
77,516 KB
testcase_22 AC 129 ms
77,696 KB
testcase_23 AC 727 ms
81,000 KB
testcase_24 AC 296 ms
77,952 KB
testcase_25 AC 384 ms
79,272 KB
testcase_26 AC 744 ms
83,072 KB
testcase_27 AC 81 ms
77,308 KB
testcase_28 AC 125 ms
77,824 KB
testcase_29 AC 54 ms
69,760 KB
testcase_30 AC 798 ms
83,004 KB
testcase_31 AC 98 ms
77,400 KB
testcase_32 AC 81 ms
77,056 KB
testcase_33 AC 87 ms
77,672 KB
testcase_34 AC 76 ms
77,184 KB
testcase_35 AC 87 ms
76,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque

input = sys.stdin.buffer.readline

H, W = map(int, input().split())
table = list(list(map(int, input().split())) for _ in range(H))
flag_all = False
final_color = 0
Q = int(input())
for _ in range(Q):
    R, C, X = map(int, input().split())
    R -= 1
    C -= 1
    if flag_all:
        final_color = X
    else:
        if table[R][C] == X:
            continue
        table[R][C] = X
        d = deque([(R, C)])
        ct = 0
        while d:
            r, c = d.pop()
            ct += 1
            for dr, dc in ((1, 0), (0, 1), (-1, 0), (0, -1)):
                rdr = r + dr
                cdc = c + dc
                if 0 <= rdr < H and 0 <= cdc < W and table[rdr][cdc] != X:
                    table[rdr][cdc] = X
                    d.append((rdr, cdc))
        if ct == H * W:
            flag_all = True
            final_color = X
if flag_all:
    for _ in range(H):
        print(*([final_color] * W))
else:
    for row in table:
        print(*row)
0