結果
| 問題 | No.366 ロボットソート |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-10 17:00:33 |
| 言語 | Python3 (3.14.3 + numpy 2.4.2 + scipy 1.17.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 911 bytes |
| 記録 | |
| コンパイル時間 | 615 ms |
| コンパイル使用メモリ | 20,680 KB |
| 実行使用メモリ | 15,484 KB |
| 最終ジャッジ日時 | 2026-02-10 17:00:40 |
| 合計ジャッジ時間 | 5,767 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 WA * 8 |
ソースコード
import sys
from collections import defaultdict, deque
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = sorted(a)
# lưu tất cả vị trí của từng giá trị
pos = defaultdict(deque)
for i in range(n):
pos[b[i]].append(i)
ans = 0
for i in range(k):
idx = []
j = i
while j < n:
idx.append(j)
j += k
sz = len(idx)
visited = [False]*sz
for j in range(sz):
if visited[j]:
continue
c = 0
d = j
while not visited[d]:
visited[d] = True
val = a[idx[d]]
location_b = pos[val].popleft()
if location_b % k != i:
print(-1)
sys.exit()
d = (location_b - i)//k
c += 1
if c > 1:
ans += c - 1
print(ans)