結果

問題 No.307 最近色塗る問題多くない?
ユーザー nebukuro09nebukuro09
提出日時 2016-10-03 15:07:13
言語 Python2
(2.7.18)
結果
RE  
実行時間 -
コード長 951 bytes
コンパイル時間 56 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 20,172 KB
最終ジャッジ日時 2024-05-01 11:19:10
合計ジャッジ時間 16,150 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,812 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 10 ms
6,940 KB
testcase_04 AC 16 ms
6,940 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 38 ms
6,940 KB
testcase_11 AC 84 ms
7,552 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 39 ms
6,944 KB
testcase_15 AC 59 ms
7,168 KB
testcase_16 AC 60 ms
6,940 KB
testcase_17 AC 765 ms
9,792 KB
testcase_18 AC 2,934 ms
13,176 KB
testcase_19 AC 2,090 ms
13,000 KB
testcase_20 AC 16 ms
6,940 KB
testcase_21 AC 1,503 ms
12,492 KB
testcase_22 AC 1,298 ms
14,836 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

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(q[-1][2])]*W)
            exit()
        
for i in xrange(H):
    print ' '.join(map(str, board[i]))
0