結果

問題 No.13 囲みたい!
ユーザー szkhtsszkhts
提出日時 2020-12-31 11:26:43
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 1,009 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 10,876 KB
実行使用メモリ 9,060 KB
最終ジャッジ日時 2023-07-30 15:30:00
合計ジャッジ時間 1,608 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 16 ms
8,356 KB
testcase_03 RE -
testcase_04 WA -
testcase_05 RE -
testcase_06 WA -
testcase_07 AC 33 ms
8,580 KB
testcase_08 AC 34 ms
8,456 KB
testcase_09 WA -
testcase_10 AC 19 ms
8,276 KB
testcase_11 AC 30 ms
8,572 KB
testcase_12 AC 17 ms
8,240 KB
testcase_13 AC 22 ms
8,432 KB
testcase_14 AC 22 ms
8,396 KB
testcase_15 AC 17 ms
8,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def inner_range(y, x):
    return y >= 0 and x >= 0 and y < H and x < W

def check(y, x, py, px):
    matrix[y][x] = True
    
    for dy, dx in zip(DY, DX):
        ny = y + dy
        nx = x + dx
        
        if nx == px and ny == py:
            continue
        
        if not inner_range(ny, nx):
            continue
        
        if area[y][x] != area[ny][nx]:
            continue
        
        if matrix[ny][nx]:
            return True
        
        if check(ny, nx, y, x):
            return True
        
    return False
        

W, H = map(int, input().split())
matrix = [[False for _ in range(W + 2)] for _ in range(H + 2)]

DY = [1, 0, -1, 0]
DX = [0, 1, 0, -1]

area = []
for _ in range(H):
    area.append(list(map(int, input().split())))

judge = False
for i in range(H):
    for j in range(W):
        if matrix[i][j]:
            continue
        
        if check(i, j, -1, -1):
            print("possiple")
            sys.exit()
        
print("impossible")
0