結果
問題 | No.13 囲みたい! |
ユーザー | square1001 |
提出日時 | 2022-02-17 12:06:16 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 43 ms / 5,000 ms |
コード長 | 797 bytes |
コンパイル時間 | 339 ms |
コンパイル使用メモリ | 10,892 KB |
実行使用メモリ | 13,220 KB |
最終ジャッジ日時 | 2023-09-11 17:37:31 |
合計ジャッジ時間 | 1,454 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
8,184 KB |
testcase_01 | AC | 16 ms
8,352 KB |
testcase_02 | AC | 17 ms
8,192 KB |
testcase_03 | AC | 37 ms
10,864 KB |
testcase_04 | AC | 43 ms
13,220 KB |
testcase_05 | AC | 36 ms
10,424 KB |
testcase_06 | AC | 33 ms
8,668 KB |
testcase_07 | AC | 32 ms
8,564 KB |
testcase_08 | AC | 33 ms
8,528 KB |
testcase_09 | AC | 32 ms
8,420 KB |
testcase_10 | AC | 20 ms
8,280 KB |
testcase_11 | AC | 29 ms
8,520 KB |
testcase_12 | AC | 18 ms
8,352 KB |
testcase_13 | AC | 21 ms
8,392 KB |
testcase_14 | AC | 22 ms
8,420 KB |
testcase_15 | AC | 17 ms
8,292 KB |
ソースコード
import sys sys.setrecursionlimit(12000) # Input W, H = map(int, input().split()) A = [ list(map(int, input().split())) for i in range(H) ] # DFS Function def dfs(x, y, A, vis): dx = [ 1, 0, -1, 0 ] dy = [ 0, 1, 0, -1 ] vis[x][y] = True cnts = (1, 0) for i in range(4): tx, ty = x + dx[i], y + dy[i] if 0 <= tx and tx < H and 0 <= ty and ty < W and A[tx][ty] == A[x][y]: if not vis[tx][ty]: res = dfs(tx, ty, A, vis) cnts = (cnts[0] + res[0], cnts[1] + res[1]) cnts = (cnts[0], cnts[1] + 1) return cnts # DFS vis = [ [ False ] * W for i in range(H) ] answer = False for i in range(H): for j in range(W): if not vis[i][j]: res = dfs(i, j, A, vis) if res[1] // 2 != res[0] - 1: answer = True # Output if answer: print("possible") else: print("impossible")