結果

問題 No.366 ロボットソート
ユーザー mlihua09mlihua09
提出日時 2020-09-20 08:45:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 537 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 76,104 KB
最終ジャッジ日時 2023-09-06 16:13:00
合計ジャッジ時間 3,262 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,040 KB
testcase_01 AC 70 ms
70,984 KB
testcase_02 AC 71 ms
70,888 KB
testcase_03 AC 72 ms
70,892 KB
testcase_04 AC 73 ms
71,016 KB
testcase_05 AC 73 ms
70,828 KB
testcase_06 AC 71 ms
70,884 KB
testcase_07 AC 72 ms
70,948 KB
testcase_08 AC 72 ms
70,676 KB
testcase_09 AC 73 ms
70,976 KB
testcase_10 AC 72 ms
71,008 KB
testcase_11 AC 73 ms
71,104 KB
testcase_12 AC 73 ms
71,008 KB
testcase_13 AC 72 ms
71,012 KB
testcase_14 AC 73 ms
70,892 KB
testcase_15 AC 72 ms
70,960 KB
testcase_16 AC 73 ms
71,128 KB
testcase_17 AC 76 ms
75,180 KB
testcase_18 AC 80 ms
76,104 KB
testcase_19 AC 79 ms
75,616 KB
testcase_20 AC 71 ms
71,040 KB
testcase_21 AC 72 ms
71,128 KB
testcase_22 AC 79 ms
75,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int, input().split())

A = list(map(int, input().split()))

B = A.copy()
B.sort()
ans = 0

for i in range(N):
    
    if A[i] != B[i]:
        
        x = A[i]
        for j in range(i + K, N, K):
            if A[j] == B[i]:
                A[j] = x
                A[i] = B[i]
                ans += 1
                break
            
            else:
                A[j], x = x, A[j]
                ans += 1
        
        if A[i] != B[i]:
            print(-1)
            exit()
            
print(ans)
        
0