結果

問題 No.366 ロボットソート
ユーザー tookunn_1213tookunn_1213
提出日時 2016-04-29 23:36:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,429 ms / 2,000 ms
コード長 564 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-15 06:03:56
合計ジャッジ時間 3,070 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,752 KB
testcase_01 AC 28 ms
10,752 KB
testcase_02 AC 27 ms
10,752 KB
testcase_03 AC 27 ms
10,752 KB
testcase_04 AC 29 ms
10,752 KB
testcase_05 AC 29 ms
10,752 KB
testcase_06 AC 29 ms
10,752 KB
testcase_07 AC 26 ms
10,880 KB
testcase_08 AC 28 ms
10,752 KB
testcase_09 AC 27 ms
10,752 KB
testcase_10 AC 28 ms
10,752 KB
testcase_11 AC 29 ms
10,880 KB
testcase_12 AC 29 ms
10,880 KB
testcase_13 AC 28 ms
10,880 KB
testcase_14 AC 30 ms
10,880 KB
testcase_15 AC 29 ms
10,880 KB
testcase_16 AC 32 ms
10,880 KB
testcase_17 AC 45 ms
11,008 KB
testcase_18 AC 127 ms
10,880 KB
testcase_19 AC 105 ms
11,008 KB
testcase_20 AC 28 ms
11,008 KB
testcase_21 AC 32 ms
10,880 KB
testcase_22 AC 1,429 ms
10,880 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