結果
問題 |
No.307 最近色塗る問題多くない?
|
ユーザー |
![]() |
提出日時 | 2015-11-27 05:51:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,377 ms / 4,000 ms |
コード長 | 1,192 bytes |
コンパイル時間 | 530 ms |
コンパイル使用メモリ | 82,132 KB |
実行使用メモリ | 104,444 KB |
最終ジャッジ日時 | 2024-11-21 21:46:59 |
合計ジャッジ時間 | 9,583 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 36 |
ソースコード
#import time #start = time.clock() h,w = map(int, input().split()) a = [] for i in range(h): a.append( list(map(int, input().split())) ) q_ = [None] * (h*w) ptr = 0 def bfs (start, color) : global a global q_ global ptr if a[start // w][start % w] == color : return 0 dx = [0,0,1,-1] dy = [1,-1,0,0] ret = 0 q_[ptr] = start ptr += 1 a[start // w][start % w] = color while ptr != 0 : pos = q_[ptr-1] ptr -= 1 x = pos % w y = pos // w ret += 1; for k in range(4) : xx = x + dx[k] yy = y + dy[k] next_pos = yy * w + xx if xx<0 or xx >= w or yy<0 or yy>=h : continue if (a[yy][xx] == color) : continue a[yy][xx] = color q_[ptr] = next_pos ptr += 1 return ret; filled = False; last = -1; q = int(input()) for i in range(q): r,c,x = map(int, input().split()) r = r-1; c = c-1; last = x; if (a[r][c] == x or filled == True) : continue cnt = bfs(r * w + c, x) if (w*h == cnt) : filled = True #import sys #print >> sys.stderr, filled if (filled == True) : for i in range(h): a[i] = str(last) * w for i in range(h): print ( ' '.join(map(str, a[i])) ) #print >> sys.stderr, time.clock() - start , "sec"