結果

問題 No.307 最近色塗る問題多くない?
ユーザー H3PO4H3PO4
提出日時 2022-08-21 09:18:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,004 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 82,340 KB
実行使用メモリ 83,072 KB
最終ジャッジ日時 2024-04-18 08:56:39
合計ジャッジ時間 7,460 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,016 KB
testcase_01 AC 43 ms
53,888 KB
testcase_02 AC 40 ms
54,400 KB
testcase_03 AC 43 ms
53,504 KB
testcase_04 AC 58 ms
67,072 KB
testcase_05 AC 46 ms
60,800 KB
testcase_06 AC 47 ms
61,568 KB
testcase_07 AC 80 ms
76,980 KB
testcase_08 WA -
testcase_09 AC 100 ms
77,300 KB
testcase_10 AC 72 ms
73,984 KB
testcase_11 AC 81 ms
77,312 KB
testcase_12 AC 44 ms
54,272 KB
testcase_13 AC 67 ms
76,472 KB
testcase_14 AC 61 ms
69,120 KB
testcase_15 AC 60 ms
70,860 KB
testcase_16 AC 63 ms
70,784 KB
testcase_17 AC 93 ms
76,928 KB
testcase_18 AC 168 ms
77,356 KB
testcase_19 AC 148 ms
78,220 KB
testcase_20 AC 52 ms
65,792 KB
testcase_21 AC 137 ms
77,464 KB
testcase_22 AC 157 ms
77,568 KB
testcase_23 AC 711 ms
81,280 KB
testcase_24 AC 286 ms
77,824 KB
testcase_25 AC 369 ms
79,016 KB
testcase_26 AC 698 ms
83,072 KB
testcase_27 AC 81 ms
77,304 KB
testcase_28 WA -
testcase_29 AC 55 ms
70,272 KB
testcase_30 AC 753 ms
82,688 KB
testcase_31 AC 101 ms
77,436 KB
testcase_32 AC 79 ms
76,872 KB
testcase_33 AC 88 ms
78,080 KB
testcase_34 AC 75 ms
76,928 KB
testcase_35 AC 80 ms
77,316 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 table[R][C] == X:
        continue
    if flag_all:
        final_color = X
    else:
        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