結果

問題 No.366 ロボットソート
ユーザー Tawara
提出日時 2016-07-04 20:17:13
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 321 bytes
コンパイル時間 608 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-10-12 20:13:01
合計ジャッジ時間 4,038 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16 WA * 1 TLE * 1 -- * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K=map(int,raw_input().split())
a = map(int,raw_input().split())
for o,(p,v) in enumerate(sorted(enumerate(a),key=lambda x:x[1])):
	a[p] = o
i = ans = 0
while i < N:
	if a[i] == i:
		i+=1
		continue
	if i-a[i] % K != 0:
		ans = -1
		break
	j=i
	while a[j] != j:
		a[j],a[j+K] = a[j+K],a[j]
		j += K
		ans += 1
print ans
0