結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー Konton7Konton7
提出日時 2019-05-15 00:53:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 1,566 bytes
コンパイル時間 343 ms
コンパイル使用メモリ 10,980 KB
実行使用メモリ 8,388 KB
最終ジャッジ日時 2023-09-27 12:28:10
合計ジャッジ時間 1,414 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
8,328 KB
testcase_01 AC 13 ms
8,268 KB
testcase_02 AC 14 ms
8,204 KB
testcase_03 AC 13 ms
8,300 KB
testcase_04 AC 13 ms
8,296 KB
testcase_05 AC 14 ms
8,368 KB
testcase_06 AC 14 ms
8,388 KB
testcase_07 AC 15 ms
8,324 KB
testcase_08 AC 15 ms
8,276 KB
testcase_09 AC 14 ms
8,280 KB
testcase_10 AC 14 ms
8,320 KB
testcase_11 AC 13 ms
8,296 KB
testcase_12 AC 15 ms
8,272 KB
testcase_13 AC 15 ms
8,364 KB
testcase_14 AC 14 ms
8,264 KB
testcase_15 AC 13 ms
8,272 KB
testcase_16 AC 14 ms
8,232 KB
testcase_17 AC 14 ms
8,228 KB
testcase_18 AC 14 ms
8,300 KB
testcase_19 AC 13 ms
8,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

move_list = []
for i in range(1,17):
    move_list_part = [i-4,i+4]
    if i % 4 != 0:
         move_list_part += [i+1]
    if i % 4 != 1:
         move_list_part += [i-1]
    move_list.append(move_list_part)

move_list = [ [ move_list[i][j] for j in range(len(move_list[i])) if 1 <= move_list[i][j] <= 16 ] for i in range(16) ]
move_list = [ sorted(move_list[i]) for i in range(16) ]

fit_list = []
for i in range(4):
    row = [ int(v) for v in input().split() ]
    for j in range(4):
        fit_list.append([4*i+j+1,row[j]])

def fitting(inlist):
    outlist = []
    for i in range(len(inlist)):
        if inlist[i][0] != inlist[i][1]:
            outlist.append(inlist[i])
    return outlist



def move():
    target_index = -1
    target, target2 = -1, -1
    for i in range(len(yet_fit_list)):
        if yet_fit_list[i][1] == 0:
            target = yet_fit_list[i][0]
            target_index = i

    if target_index != -1:
        for i in range(len(yet_fit_list)):
            if yet_fit_list[i][1] == target:
                target2 = yet_fit_list[i][0]
                target2_index = i

        if target2 in move_list[target-1]:
            yet_fit_list[target_index][1] = target
            yet_fit_list[target2_index][1] = 0
    else:
        pass
    return

def judge():
    if yet_fit_list == [[16,0]]:
        print("Yes")
        return 1
    else:
        return 0
        
yet_fit_list = fitting(fit_list)

for i in range(16):
    if judge() == 1:
        break
    move()
    yet_fit_list = fitting(yet_fit_list)
else:
    print("No")
0