結果

問題 No.13 囲みたい!
ユーザー szkhtsszkhts
提出日時 2020-12-31 11:06:31
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
RE  
実行時間 -
コード長 1,029 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 11,080 KB
実行使用メモリ 9,184 KB
最終ジャッジ日時 2023-07-30 15:08:09
合計ジャッジ時間 1,481 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,344 KB
testcase_01 AC 18 ms
8,364 KB
testcase_02 AC 16 ms
8,348 KB
testcase_03 RE -
testcase_04 AC 20 ms
8,552 KB
testcase_05 RE -
testcase_06 AC 20 ms
8,588 KB
testcase_07 AC 34 ms
8,532 KB
testcase_08 AC 35 ms
8,516 KB
testcase_09 AC 35 ms
8,520 KB
testcase_10 AC 22 ms
8,316 KB
testcase_11 AC 30 ms
8,536 KB
testcase_12 AC 17 ms
8,312 KB
testcase_13 AC 22 ms
8,400 KB
testcase_14 AC 23 ms
8,540 KB
testcase_15 AC 16 ms
8,244 KB
権限があれば一括ダウンロードができます

ソースコード

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("possible")
else:
    print("impossible")
0