結果

問題 No.307 最近色塗る問題多くない?
コンテスト
ユーザー Meso Meso
提出日時 2025-12-11 18:51:49
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 766 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 249 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 17,960 KB
最終ジャッジ日時 2025-12-11 18:51:56
合計ジャッジ時間 6,380 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 TLE * 1 -- * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import deque
import sys
input = sys.stdin.readline

h, w = map(int, input().split())
grid = [list(map(int, input().split())) for _ in range(h)]

dy = [-1, 1, 0, 0]
dx = [0, 0, -1, 1]

def bfs(r, c, x):
    original = grid[r][c]
    if original == x:
        return

    q = deque()
    q.append((r, c))
    grid[r][c] = x

    while q:
        cy, cx = q.popleft()
        for i in range(4):
            ny = cy + dy[i]
            nx = cx + dx[i]
            if 0 <= ny < h and 0 <= nx < w:
                if grid[ny][nx] == original:
                    grid[ny][nx] = x
                    q.append((ny, nx))

Q = int(input())
for _ in range(Q):
    r, c, x = map(int, input().split())
    bfs(r - 1, c - 1, x)

for row in grid:
    print(*row)
0