結果
問題 | No.228 ゆきこちゃんの 15 パズル |
ユーザー | matsu7874 |
提出日時 | 2015-11-29 17:58:46 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 36 ms / 5,000 ms |
コード長 | 1,561 bytes |
コンパイル時間 | 87 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-09-14 05:10:12 |
合計ジャッジ時間 | 1,496 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
10,880 KB |
testcase_01 | AC | 31 ms
10,752 KB |
testcase_02 | AC | 31 ms
10,880 KB |
testcase_03 | AC | 35 ms
10,880 KB |
testcase_04 | AC | 31 ms
10,752 KB |
testcase_05 | AC | 30 ms
10,880 KB |
testcase_06 | AC | 33 ms
10,880 KB |
testcase_07 | AC | 32 ms
10,752 KB |
testcase_08 | AC | 34 ms
10,752 KB |
testcase_09 | AC | 33 ms
10,880 KB |
testcase_10 | AC | 31 ms
11,008 KB |
testcase_11 | AC | 32 ms
11,008 KB |
testcase_12 | AC | 34 ms
10,880 KB |
testcase_13 | AC | 36 ms
10,880 KB |
testcase_14 | AC | 34 ms
11,008 KB |
testcase_15 | AC | 36 ms
11,136 KB |
testcase_16 | AC | 34 ms
10,880 KB |
testcase_17 | AC | 34 ms
10,880 KB |
testcase_18 | AC | 35 ms
11,136 KB |
testcase_19 | AC | 34 ms
10,880 KB |
ソースコード
import collections A = [] for i in range(4): A += list(map(int, input().split())) # print(A) dq = collections.deque() dq.append([[False] * 16, A[:]]) while dq: moved, puzzle = dq.popleft() # print(puzzle,moved) if puzzle == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0]: print('Yes') exit() zero = puzzle.index(0) if zero >= 4: t = puzzle[zero - 4] if not moved[t]: next_puzzle = puzzle[:] next_puzzle[zero] = t next_puzzle[zero - 4] = 0 next_moved = moved[:] next_moved[t] = True dq.append([next_moved, next_puzzle]) if zero % 4 > 0: t = puzzle[zero - 1] if not moved[t]: next_puzzle = puzzle[:] next_puzzle[zero] = t next_puzzle[zero - 1] = 0 next_moved = moved[:] next_moved[t] = True dq.append([next_moved, next_puzzle]) if zero < 12: t = puzzle[zero + 4] if not moved[t]: next_puzzle = puzzle[:] next_puzzle[zero] = t next_puzzle[zero + 4] = 0 next_moved = moved[:] next_moved[t] = True dq.append([next_moved, next_puzzle]) if zero % 4 < 3: t = puzzle[zero + 1] if not moved[t]: next_puzzle = puzzle[:] next_puzzle[zero] = t next_puzzle[zero + 1] = 0 next_moved = moved[:] next_moved[t] = True dq.append([next_moved, next_puzzle]) print('No')