結果

問題 No.366 ロボットソート
ユーザー 👑 KazunKazun
提出日時 2021-01-19 22:09:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 494 bytes
コンパイル時間 1,652 ms
コンパイル使用メモリ 86,568 KB
実行使用メモリ 76,096 KB
最終ジャッジ日時 2023-08-22 18:21:24
合計ジャッジ時間 4,209 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,076 KB
testcase_01 AC 70 ms
70,928 KB
testcase_02 AC 69 ms
71,076 KB
testcase_03 AC 70 ms
71,312 KB
testcase_04 AC 69 ms
71,080 KB
testcase_05 AC 70 ms
71,232 KB
testcase_06 AC 69 ms
71,156 KB
testcase_07 AC 70 ms
71,068 KB
testcase_08 AC 71 ms
71,160 KB
testcase_09 AC 70 ms
71,420 KB
testcase_10 AC 69 ms
71,236 KB
testcase_11 AC 77 ms
75,956 KB
testcase_12 AC 79 ms
75,956 KB
testcase_13 AC 71 ms
71,304 KB
testcase_14 AC 71 ms
71,400 KB
testcase_15 AC 70 ms
71,280 KB
testcase_16 AC 76 ms
75,904 KB
testcase_17 AC 76 ms
76,096 KB
testcase_18 AC 77 ms
75,884 KB
testcase_19 AC 75 ms
75,952 KB
testcase_20 AC 72 ms
71,232 KB
testcase_21 AC 76 ms
75,824 KB
testcase_22 AC 82 ms
75,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def f(A):
    N=len(A)
    x=0
    for i in range(N):
        for j in range(N-1):
            if A[j]>A[j+1]:
                A[j],A[j+1]=A[j+1],A[j]
                x+=1
    return x

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

B=[[] for _ in range(K)]
t=0
for a in A:
    B[t].append(a)
    t=(t+1)%K

A.sort()

X=0
for b in B:
    X+=f(b)

B=[sorted(x)[::-1] for x in B]
C=[]
t=0
for i in range(N):
    x=B[t].pop()
    C.append(x)
    t=(t+1)%K

print(X if A==C else -1)
0