結果
問題 |
No.307 最近色塗る問題多くない?
|
ユーザー |
![]() |
提出日時 | 2015-11-27 10:21:17 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,192 bytes |
コンパイル時間 | 125 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 14,008 KB |
最終ジャッジ日時 | 2024-09-13 23:02:08 |
合計ジャッジ時間 | 12,940 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 TLE * 1 -- * 12 |
ソースコード
#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"