結果

問題 No.307 最近色塗る問題多くない?
ユーザー nebukuro09nebukuro09
提出日時 2016-10-03 15:08:37
言語 PyPy2
(7.3.15)
結果
MLE  
実行時間 -
コード長 953 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 77,108 KB
実行使用メモリ 268,136 KB
最終ジャッジ日時 2024-05-01 11:19:55
合計ジャッジ時間 22,355 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
75,272 KB
testcase_01 AC 68 ms
75,652 KB
testcase_02 AC 65 ms
75,268 KB
testcase_03 AC 64 ms
75,824 KB
testcase_04 AC 93 ms
78,480 KB
testcase_05 AC 71 ms
75,580 KB
testcase_06 AC 76 ms
77,976 KB
testcase_07 AC 137 ms
79,524 KB
testcase_08 AC 249 ms
95,864 KB
testcase_09 AC 151 ms
84,404 KB
testcase_10 AC 121 ms
79,672 KB
testcase_11 AC 129 ms
80,524 KB
testcase_12 AC 67 ms
75,796 KB
testcase_13 AC 125 ms
83,440 KB
testcase_14 AC 91 ms
78,372 KB
testcase_15 AC 92 ms
78,356 KB
testcase_16 AC 95 ms
78,748 KB
testcase_17 AC 226 ms
89,780 KB
testcase_18 AC 588 ms
125,772 KB
testcase_19 AC 479 ms
111,976 KB
testcase_20 AC 76 ms
78,208 KB
testcase_21 AC 340 ms
97,516 KB
testcase_22 AC 360 ms
113,480 KB
testcase_23 MLE -
testcase_24 AC 1,084 ms
143,672 KB
testcase_25 AC 1,652 ms
234,468 KB
testcase_26 MLE -
testcase_27 TLE -
testcase_28 AC 245 ms
99,756 KB
testcase_29 AC 106 ms
81,052 KB
testcase_30 MLE -
testcase_31 AC 1,534 ms
84,916 KB
testcase_32 AC 142 ms
83,976 KB
testcase_33 AC 97 ms
80,792 KB
testcase_34 AC 265 ms
83,856 KB
testcase_35 AC 284 ms
87,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

dr = [0, 0, 1, -1]
dc = [1, -1, 0, 0]

H, W = map(int, raw_input().split())
board = [map(int, raw_input().split()) for _ in xrange(H)]
Q = input()
queries = [map(int, raw_input().split()) for _ in xrange(Q)]

def dfs(r, c, color):
    visited = set()
    stack = [(r, c)]
    while len(stack) > 0:
        r, c = stack.pop()
        if (r, c) in visited or board[r][c] == color:
            continue
        visited.add((r, c))
        board[r][c] = color
        for i in xrange(4):
            nr, nc = r+dr[i], c+dc[i]
            if nr < 0 or nr >= H or nc < 0 or nc >= W or (nr, nc) in visited:
                continue
            stack.append((nr, nc))

for q in queries:
    dfs(q[0]-1, q[1]-1, q[2])
    if all(all(board[0][0]==board[i][j] for j in xrange(W)) for i in xrange(H)):
        for i in xrange(H):
            print ' '.join([str(queries[-1][2])]*W)
        exit()
        
for i in xrange(H):
    print ' '.join(map(str, board[i]))
0