結果
問題 | No.307 最近色塗る問題多くない? |
ユーザー |
![]() |
提出日時 | 2021-01-13 04:33:50 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,016 ms / 4,000 ms |
コード長 | 821 bytes |
コンパイル時間 | 213 ms |
コンパイル使用メモリ | 82,296 KB |
実行使用メモリ | 116,268 KB |
最終ジャッジ日時 | 2024-11-21 18:56:44 |
合計ジャッジ時間 | 8,856 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 36 |
ソースコード
def bfs(i,j,x): global cnt0 if b[i][j]==x: return c = 0 b[i][j] = x q = [(i,j)] while q: vi,vj = q.pop() c += 1 for ni,nj in [(vi-1,vj),(vi+1,vj),(vi,vj-1),(vi,vj+1)]: if 0 <= ni < h and 0 <= nj < w and b[ni][nj] != x: b[ni][nj] = x q.append((ni,nj)) cnt0 += c if x==0 else -c return h,w = map(int,input().split()) b = [list(map(int,input().split())) for _ in range(h)] cnt0 = 0 for i in range(h): for j in range(w): if b[i][j]==0: cnt0 += 1 q = int(input()) for _ in range(q): r,c,x = map(int,input().split()) if cnt0 != 0 and cnt0 != h*w: bfs(r-1,c-1,x) if cnt0 in [0,h*w]: for i in range(h): for j in range(w): b[i][j] = x for i in range(h): print(*b[i])