結果

問題 No.366 ロボットソート
コンテスト
ユーザー Đức Minh Vũ
提出日時 2026-02-10 17:19:45
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 549 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 635 ms
コンパイル使用メモリ 20,688 KB
実行使用メモリ 15,484 KB
最終ジャッジ日時 2026-02-10 17:19:51
合計ジャッジ時間 5,130 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys

def count(arr):
    inv = 0
    n = len(arr)
    for i in range(n):
        for j in range(i + 1, n):
            if arr[i] > arr[j]:
                inv += 1
    return inv

n, k = map(int, input().split())
a = list(map(int, input().split()))

b = sorted(a)

ans = 0

for start in range(k):
    cur = []
    need = []
    
    i = start
    while i < n:
        cur.append(a[i])
        need.append(b[i])
        i += k
    
    if sorted(cur) != sorted(need):
        print(-1)
        sys.exit()
    
    ans += count(cur)

print(ans)
0