結果

問題 No.366 ロボットソート
ユーザー rlangevin
提出日時 2023-01-06 00:15:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 518 bytes
コンパイル時間 406 ms
コンパイル使用メモリ 82,236 KB
実行使用メモリ 61,680 KB
最終ジャッジ日時 2024-11-29 16:40:19
合計ジャッジ時間 2,139 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

def calc(X):
    M = len(X)
    val = 0
    for i in range(M):
        for j in range(i + 1, M):
            if X[i] > X[j]:
                val += 1
    return val

N, K = map(int, input().split())
A = list(map(int, input().split()))
L = [[] for i in range(K)]
for i in range(N):
    L[i%K].append(A[i])

ans = 0
for i in range(K):
    ans += calc(L[i])
    
D = []
for i in range(K):
    L[i].sort(reverse=True)

for i in range(N):
    D.append(L[i%K].pop())
A.sort()
if A == D:
    print(ans)
else:
    print(-1)   
0