結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー aka_satana_haaka_satana_ha
提出日時 2017-11-28 13:55:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 1,589 bytes
コンパイル時間 127 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 8,348 KB
最終ジャッジ日時 2023-08-18 09:03:18
合計ジャッジ時間 1,728 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,320 KB
testcase_01 AC 17 ms
8,176 KB
testcase_02 AC 17 ms
8,348 KB
testcase_03 AC 17 ms
8,196 KB
testcase_04 AC 16 ms
8,300 KB
testcase_05 AC 16 ms
8,348 KB
testcase_06 AC 17 ms
8,292 KB
testcase_07 AC 17 ms
8,200 KB
testcase_08 AC 17 ms
8,336 KB
testcase_09 AC 17 ms
8,288 KB
testcase_10 AC 17 ms
8,180 KB
testcase_11 AC 17 ms
8,176 KB
testcase_12 AC 17 ms
8,316 KB
testcase_13 AC 17 ms
8,152 KB
testcase_14 AC 17 ms
8,336 KB
testcase_15 AC 17 ms
8,172 KB
testcase_16 AC 17 ms
8,268 KB
testcase_17 AC 17 ms
8,264 KB
testcase_18 AC 16 ms
8,212 KB
testcase_19 AC 17 ms
8,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

goal=[]
for i in range(4):
    line=[int(i) for i in input().split()]
    goal.append(line)
# print(goal)

#init
puzzle=[]
puzzle.append([1,2,3,4])
puzzle.append([5,6,7,8])
puzzle.append([9,10,11,12])
puzzle.append([13,14,15,0])
moved=[[False for i in range(4)] for j in range(4)]

zero_pos=[3,3]
while(1):
    # print(zero_pos)
    # for i in range(4):
    #     print(puzzle[i])
    # print('\n')
    if puzzle==goal:
        print("Yes")
        break
    zero_pos_y=zero_pos[0]
    zero_pos_x=zero_pos[1]
    goal_num=goal[zero_pos_y][zero_pos_x]
    #↑
    if zero_pos_y!=0:
        if goal_num==puzzle[zero_pos_y-1][zero_pos_x]:
            zero_pos=[zero_pos_y-1,zero_pos_x]
            puzzle[zero_pos_y-1][zero_pos_x]=0
            puzzle[zero_pos_y][zero_pos_x]=goal_num
            continue
    #↓
    if zero_pos_y!=3:
        if goal_num==puzzle[zero_pos_y+1][zero_pos_x]:
            zero_pos=[zero_pos_y+1,zero_pos_x]
            puzzle[zero_pos_y+1][zero_pos_x]=0
            puzzle[zero_pos_y][zero_pos_x]=goal_num
            continue
    #←
    if zero_pos_x!=0:
        if goal_num==puzzle[zero_pos_y][zero_pos_x-1]:
            zero_pos=[zero_pos_y,zero_pos_x-1]
            puzzle[zero_pos_y][zero_pos_x-1]=0
            puzzle[zero_pos_y][zero_pos_x]=goal_num
            continue
    #→
    if zero_pos_x!=3:
        if goal_num==puzzle[zero_pos_y][zero_pos_x+1]:
            zero_pos=[zero_pos_y,zero_pos_x+1]
            puzzle[zero_pos_y][zero_pos_x+1]=0
            puzzle[zero_pos_y][zero_pos_x]=goal_num
            continue
    print("No")
    break
0