結果

問題 No.13 囲みたい!
ユーザー HIROPON87069639HIROPON87069639
提出日時 2016-02-20 15:01:20
言語 Python2
(2.7.18)
結果
AC  
実行時間 57 ms / 5,000 ms
コード長 1,360 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 6,912 KB
最終ジャッジ日時 2024-04-21 12:22:44
合計ジャッジ時間 1,048 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
6,272 KB
testcase_01 AC 8 ms
6,272 KB
testcase_02 AC 9 ms
6,144 KB
testcase_03 AC 34 ms
6,528 KB
testcase_04 AC 16 ms
6,528 KB
testcase_05 AC 57 ms
6,656 KB
testcase_06 AC 19 ms
6,528 KB
testcase_07 AC 54 ms
6,528 KB
testcase_08 AC 55 ms
6,912 KB
testcase_09 AC 54 ms
6,912 KB
testcase_10 AC 16 ms
6,528 KB
testcase_11 AC 44 ms
6,656 KB
testcase_12 AC 12 ms
6,400 KB
testcase_13 AC 23 ms
6,528 KB
testcase_14 AC 25 ms
6,528 KB
testcase_15 AC 10 ms
6,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
W, H = map(int, raw_input().split())
matA = [[0 for i in range(0, W)] for j in range(0, H)]
for i in range(0, H):
    tmp = map(int, (raw_input().split()))
    for j in range(0, W):
        matA[i][j] = tmp[j]
matB = [[0 for i in range(0, W)] for j in range(0, H)]
flag = 0
delx = (0, 1, -1, 0, 0)
dely = (0, 0, 0, 1, -1)
delm = (0, 2, 1, 4, 3)
staci = []
stacj = []
stacd = []
cnt = 0
num = 0
for i in range(0, H):
    for j in range(0, W):
        if matB[i][j] == 0:
            cnt += 1
            num = matA[i][j]
            staci.append(i)
            stacj.append(j)
            stacd.append(0)
            while len(staci) != 0:
                ii = staci.pop()
                jj = stacj.pop()
                di = stacd.pop()
                matB[ii][jj] = cnt
                for k in range(1, 5):
                    iii = ii + dely[k]
                    jjj = jj + delx[k]
                    if 0 <= iii < H and 0 <= jjj < W:
                        if matA[ii][jj] == matA[iii][jjj] and k != delm[di]:
                            staci.append(iii)
                            stacj.append(jjj)
                            stacd.append(k)
                        if matB[ii][jj] == matB[iii][jjj] and k != delm[di]:
                            print "possible"
                            exit()
print "impossible"




0