結果

問題 No.13 囲みたい!
ユーザー szkhtsszkhts
提出日時 2020-12-31 11:05:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,029 bytes
コンパイル時間 116 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-17 16:13:17
合計ジャッジ時間 1,384 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 RE -
testcase_04 WA -
testcase_05 RE -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def check(y, x, pre):
    matrix[y][x] = True
    dy = [1, 0, -1, 0]
    dx = [0, 1, 0, -1]
    
    for k in range(4):
        if pre == k:
            continue
        
        ny = y + dy[k]
        nx = x + dx[k]
        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, (k + 2) % 4):
            return True
        
    return False
        

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

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
        
        judge = check(i, j, -1)
        if judge:
            break
    if judge:
        break

if judge:
    print("possiple")
else:
    print("impossiple")
0