結果

問題 No.366 ロボットソート
ユーザー tookunn_1213tookunn_1213
提出日時 2016-04-29 23:36:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 564 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 76,160 KB
最終ジャッジ日時 2023-08-28 15:12:20
合計ジャッジ時間 3,088 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,476 KB
testcase_01 AC 73 ms
71,372 KB
testcase_02 AC 71 ms
71,168 KB
testcase_03 AC 69 ms
71,380 KB
testcase_04 AC 72 ms
71,408 KB
testcase_05 AC 72 ms
71,444 KB
testcase_06 AC 72 ms
71,548 KB
testcase_07 AC 72 ms
71,456 KB
testcase_08 AC 71 ms
71,372 KB
testcase_09 AC 71 ms
71,372 KB
testcase_10 AC 70 ms
71,128 KB
testcase_11 AC 71 ms
71,548 KB
testcase_12 AC 72 ms
71,412 KB
testcase_13 AC 72 ms
71,396 KB
testcase_14 AC 75 ms
75,768 KB
testcase_15 AC 70 ms
71,492 KB
testcase_16 AC 77 ms
75,880 KB
testcase_17 AC 79 ms
75,928 KB
testcase_18 AC 84 ms
76,160 KB
testcase_19 AC 81 ms
75,852 KB
testcase_20 AC 70 ms
71,252 KB
testcase_21 AC 70 ms
71,376 KB
testcase_22 AC 111 ms
75,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def check(a,b,N):
	for i in range(N):
		if a[i] not in b[i % K]:
			return False
	return True
N,K = map(int,input().split())
a = [int(i) for i in input().split()]
b = [set([]) for i in range(K)]
c = sorted([i for i in a])
for i in range(N):
	b[i % K].add(c[i])
if not check(a,b,N):
	print(-1)
else:
	cnt = 0
	while True:
		flag = True
		for i in range(N - 1):
			if a[i] > a[i + 1]:
				flag = False
		if flag:
			break
		for i in range(N):
			j = i + K
			while j < N:
				if a[j - K] > a[j]:
					a[j],a[j - K] = a[j - K],a[j]
					cnt+=1
				j += K
	print (cnt)
0