結果

問題 No.307 最近色塗る問題多くない?
ユーザー titia
提出日時 2022-11-10 01:32:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 955 ms / 4,000 ms
コード長 737 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 82,584 KB
実行使用メモリ 100,224 KB
最終ジャッジ日時 2024-07-23 06:14:27
合計ジャッジ時間 7,466 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

H,W=map(int,input().split())
MAP=[list(map(int,input().split())) for i in range(H)]

flag=0

Q=int(input())
for tests in range(Q):
    x,y,c=map(int,input().split())
    x-=1
    y-=1

    if flag==1:
        MAP[0][0]=c
        continue

    if MAP[x][y]==c:
        continue

    Q=[(x,y)]

    MAP[x][y]=c
    count=1

    while Q:
        x,y=Q.pop()
        for z,w in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]:
            if 0<=z<H and 0<=w<W and MAP[z][w]!=c:
                MAP[z][w]=c
                Q.append((z,w))
                count+=1

    if count==H*W:
        flag=1

if flag==1:
    for i in range(H):
        print(*[MAP[0][0]]*W)
else:
    for i in range(H):
        print(*MAP[i])
0