結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー mlihua09mlihua09
提出日時 2020-09-18 16:08:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 75 ms / 5,000 ms
コード長 859 bytes
コンパイル時間 874 ms
コンパイル使用メモリ 86,480 KB
実行使用メモリ 71,352 KB
最終ジャッジ日時 2023-09-04 08:53:07
合計ジャッジ時間 3,019 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,080 KB
testcase_01 AC 74 ms
71,352 KB
testcase_02 AC 73 ms
70,888 KB
testcase_03 AC 74 ms
71,036 KB
testcase_04 AC 72 ms
71,108 KB
testcase_05 AC 73 ms
71,004 KB
testcase_06 AC 72 ms
70,996 KB
testcase_07 AC 72 ms
71,040 KB
testcase_08 AC 75 ms
70,880 KB
testcase_09 AC 73 ms
70,972 KB
testcase_10 AC 73 ms
71,224 KB
testcase_11 AC 74 ms
71,088 KB
testcase_12 AC 75 ms
71,208 KB
testcase_13 AC 75 ms
71,032 KB
testcase_14 AC 74 ms
71,016 KB
testcase_15 AC 75 ms
70,972 KB
testcase_16 AC 74 ms
71,032 KB
testcase_17 AC 75 ms
71,204 KB
testcase_18 AC 74 ms
71,208 KB
testcase_19 AC 75 ms
70,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


A = [list(map(int, input().split())) for i in range(4)]

a = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 0]]

for i in range(4):
    for j in range(4):
        if A[i][j] == 0:
            x = i
            y = j
        
while x != 3 or y != 3:
    
    if x > 0 and A[x - 1][y] == a[x][y]:
        A[x][y], A[x - 1][y] = A[x - 1][y], A[x][y]
        x -= 1
        
    elif x < 3 and A[x + 1][y] == a[x][y]:
        A[x][y], A[x + 1][y] = A[x + 1][y], A[x][y]
        x += 1
        
    elif y > 0 and A[x][y - 1] == a[x][y]:
        A[x][y], A[x][y - 1] = A[x][y - 1], A[x][y]
        y -= 1
        
    elif y < 3 and A[x][y + 1] == a[x][y]:
        A[x][y], A[x][y + 1] = A[x][y + 1], A[x][y]
        y += 1
    else:
        print('No')
        exit()
        
        
if A == a:
    print('Yes')
    
else:
    print('No')
        
0