結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー MamonboMamonbo
提出日時 2015-11-05 19:55:09
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 63 ms / 5,000 ms
コード長 1,365 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 10,784 KB
実行使用メモリ 9,096 KB
最終ジャッジ日時 2023-10-11 14:06:45
合計ジャッジ時間 2,318 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
9,036 KB
testcase_01 AC 19 ms
8,468 KB
testcase_02 AC 51 ms
8,868 KB
testcase_03 AC 61 ms
8,964 KB
testcase_04 AC 42 ms
8,740 KB
testcase_05 AC 32 ms
8,656 KB
testcase_06 AC 44 ms
8,888 KB
testcase_07 AC 41 ms
8,824 KB
testcase_08 AC 48 ms
8,816 KB
testcase_09 AC 48 ms
8,952 KB
testcase_10 AC 36 ms
8,700 KB
testcase_11 AC 38 ms
8,796 KB
testcase_12 AC 59 ms
8,980 KB
testcase_13 AC 60 ms
8,940 KB
testcase_14 AC 48 ms
8,856 KB
testcase_15 AC 60 ms
9,096 KB
testcase_16 AC 53 ms
8,852 KB
testcase_17 AC 49 ms
8,808 KB
testcase_18 AC 60 ms
8,964 KB
testcase_19 AC 48 ms
8,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#coding=UTF-8
import copy
def idxp(xy):
    if xy[0] >=0 and xy[0]<4:
        if xy[1] >= 0 and xy[1]<4:
            return True
    return False

zure=[(-1,0),(1,0),(0,-1),(0,1)]
goal=[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,0]]
shokiban=[]
ans=False
for idx in range(0,4,1):
    mojir=input()
    hyo=mojir.split(' ')
    shokiban.append([int(mono) for mono in hyo])

kaikouho=[[shokiban,[]]]
while kaikouho != []:
    tmp=[]
#    print(kaikouho)
    for mono in kaikouho:
        if mono[0] == goal:
            ans=True
            break
        tgt=[]
        for idx in range(0,4,1):
            for idy in range(0,4,1):
                if mono[0][idx][idy]==0:
                    akiichi=(idx,idy)
        for idx in range(0,4,1):
            if idxp((akiichi[0]+zure[idx][0],akiichi[1]+zure[idx][1])):
                tgt.append((akiichi[0]+zure[idx][0],akiichi[1]+zure[idx][1]))
#        print(tgt)
        for myon in tgt:
            if not (mono[0][myon[0]][myon[1]] in mono[1]):
                tmpban=copy.deepcopy(mono[0])
                tmpban[myon[0]][myon[1]],tmpban[akiichi[0]][akiichi[1]]=\
                tmpban[akiichi[0]][akiichi[1]],tmpban[myon[0]][myon[1]]
                tmp.append([tmpban,mono[1]+[mono[0][myon[0]][myon[1]]]])
    kaikouho=tmp
#    if len(kaikouho)>10:
#        break
if ans:
    print('Yes')
else:
    print('No')
0