結果

問題 No.366 ロボットソート
ユーザー ntuda
提出日時 2024-08-31 16:20:49
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 673 bytes
コンパイル時間 623 ms
コンパイル使用メモリ 82,228 KB
実行使用メモリ 69,736 KB
最終ジャッジ日時 2024-08-31 16:20:52
合計ジャッジ時間 3,036 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 8 RE * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import deepcopy
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = sorted(list(set(A)))
D = dict(zip(B,range(len(B))))

for i in range(N):
    A[i] = D[A[i]]

B = [[] for _ in range(K)]
for i in range(N):
    B[i % K].append(A[i])
C = deepcopy(B)

for b in B:
    b.sort()
now = 0
for i in range(N):
    b = B[i%K][i//K]
    if now > b:
        print(-1)
        exit()
    now = b

from atcoder.fenwicktree import FenwickTree
ans = 0
for cs in C:
    if cs:
        NC = max(cs)
        ft = FenwickTree(NC + 1)
        cnt = 0
        for c in cs:
            cnt += ft.sum(c, NC + 1)
            ft.add(c, 1)
        ans += cnt
print(ans)
0