結果

問題 No.366 ロボットソート
ユーザー maguroguma
提出日時 2017-09-01 14:22:30
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 357 ms / 2,000 ms
コード長 428 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-11-06 17:22:04
合計ジャッジ時間 2,752 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-

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

ans = 0
for i in range(0, N-K, 1):
    for j in range(N-1-K, i-1, -1):
        if a[j] > a[j+K]:
            temp = a[j]
            a[j] = a[j+K]
            a[j+K] = temp
            ans += 1

is_sorted = True
for i in range(N-1):
    if a[i] > a[i+1]:
        is_sorted = False
        break

print(ans) if is_sorted else print(-1)
0