結果

問題 No.366 ロボットソート
ユーザー Snark86Snark86
提出日時 2016-04-30 00:04:55
言語 Python2
(2.7.18)
結果
AC  
実行時間 254 ms / 2,000 ms
コード長 367 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 6,668 KB
実行使用メモリ 6,184 KB
最終ジャッジ日時 2023-08-28 15:12:59
合計ジャッジ時間 2,152 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,016 KB
testcase_01 AC 11 ms
5,940 KB
testcase_02 AC 11 ms
5,888 KB
testcase_03 AC 11 ms
6,092 KB
testcase_04 AC 11 ms
5,944 KB
testcase_05 AC 10 ms
5,876 KB
testcase_06 AC 11 ms
5,860 KB
testcase_07 AC 10 ms
6,076 KB
testcase_08 AC 10 ms
5,896 KB
testcase_09 AC 11 ms
5,860 KB
testcase_10 AC 13 ms
5,876 KB
testcase_11 AC 164 ms
5,944 KB
testcase_12 AC 221 ms
6,184 KB
testcase_13 AC 31 ms
6,144 KB
testcase_14 AC 30 ms
5,860 KB
testcase_15 AC 18 ms
5,828 KB
testcase_16 AC 37 ms
5,976 KB
testcase_17 AC 60 ms
6,048 KB
testcase_18 AC 191 ms
6,176 KB
testcase_19 AC 63 ms
6,032 KB
testcase_20 AC 11 ms
6,016 KB
testcase_21 AC 42 ms
6,068 KB
testcase_22 AC 254 ms
5,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k = map(int,raw_input().split())
a = map(int,raw_input().split())
b = [sorted(a).index(i) for i in a]
cnt = 0
for i in range(n):
    if b[i]%k != i%k:
        cnt = -1
if cnt == 0:
    for i in range(n):
        j = b.index(i)
        c = cmp(i,j)
        cnt += abs(i-j)/k
        while i != j:
	        b[j], b[j+k*c] = b[j+k*c], b[j]
	        j = j+k*c
print cnt
0