結果

問題 No.13 囲みたい!
ユーザー roiti46roiti46
提出日時 2015-02-23 16:27:31
言語 Python2
(2.7.18)
結果
AC  
実行時間 41 ms / 5,000 ms
コード長 635 bytes
コンパイル時間 146 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 14,720 KB
最終ジャッジ日時 2024-04-21 12:16:55
合計ジャッジ時間 1,170 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,144 KB
testcase_01 AC 11 ms
6,144 KB
testcase_02 AC 11 ms
6,272 KB
testcase_03 AC 36 ms
10,496 KB
testcase_04 AC 41 ms
14,720 KB
testcase_05 AC 35 ms
9,856 KB
testcase_06 AC 31 ms
6,528 KB
testcase_07 AC 31 ms
6,656 KB
testcase_08 AC 32 ms
6,400 KB
testcase_09 AC 31 ms
6,528 KB
testcase_10 AC 14 ms
6,144 KB
testcase_11 AC 27 ms
6,528 KB
testcase_12 AC 12 ms
6,272 KB
testcase_13 AC 17 ms
6,400 KB
testcase_14 AC 18 ms
6,272 KB
testcase_15 AC 14 ms
6,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(100000)
dxy = zip([1,0,-1,0],[0,1,0,-1])
def dfs(x,y,c):
    A[y][x]  = -c
    res = False
    cnt = 0
    for dx,dy in dxy:
        nx,ny = x+dx,y+dy
        if 0 <= nx < W and 0 <= ny < H:
            if A[ny][nx] == c:
                res |= dfs(nx,ny,c)
            elif A[ny][nx] == -c:
                cnt += 1
    return res or cnt > 1
            
W,H = map(int,raw_input().split())
A = [map(int,raw_input().split()) for i in xrange(H)]
ans = False
for y in xrange(H):
    for x in xrange(W):
        if A[y][x] > 0:
            ans |= dfs(x,y,A[y][x])
print "possible" if ans else "impossible"
0