結果
| 問題 |
No.2946 Puyo
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-25 21:27:10 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 937 bytes |
| コンパイル時間 | 203 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 40,904 KB |
| 最終ジャッジ日時 | 2024-10-25 21:27:57 |
| 合計ジャッジ時間 | 38,105 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 42 TLE * 3 |
ソースコード
import sys
sys.setrecursionlimit(10**6)
H, W = map(int, input().split())
grid = [list(input()) for _ in range(H)]
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
visited = [[False] * W for _ in range(H)]
def dfs(x, y, char):
stack = [(x, y)]
component = [(x, y)]
visited[x][y] = True
while stack:
cx, cy = stack.pop()
for i in range(4):
nx, ny = cx + dx[i], cy + dy[i]
if 0 <= nx < H and 0 <= ny < W and not visited[nx][ny] and grid[nx][ny] == char:
visited[nx][ny] = True
stack.append((nx, ny))
component.append((nx, ny))
return component
for i in range(H):
for j in range(W):
if grid[i][j] != '.' and not visited[i][j]:
component = dfs(i, j, grid[i][j])
if len(component) >= 4:
for x, y in component:
grid[x][y] = '.'
for row in grid:
print(''.join(row))