結果
問題 |
No.1425 Yet Another Cyclic Shifts Sorting
|
ユーザー |
![]() |
提出日時 | 2021-03-18 22:36:19 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 866 bytes |
コンパイル時間 | 356 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 154,572 KB |
最終ジャッジ日時 | 2024-11-17 04:48:10 |
合計ジャッジ時間 | 10,296 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 WA * 20 |
ソースコード
from bisect import bisect_left import sys input = sys.stdin.readline class Compress: def __init__(self, vs): self.xs = list(set(vs)) self.xs.sort() def compress(self, x): return bisect_left(self.xs, x) def decompress(self, i): return self.xs[i] N = int(input()) A = list(map(int, input().split())) comp = Compress(A) A = [comp.compress(x) for x in A] prv = [N - 1] + list(range(N - 1)) nxt = list(range(1, N)) + [0] idx = [[] for _ in range(N)] for i, x in enumerate(A): idx[x].append(i) i = N - 1 ans = 0 for x in sorted(list(set(A)), reverse=True): M = len(idx[x]) j = bisect_left(idx[x], i) % M for _ in range(M): if i != idx[x][j]: i = idx[x][j] ans += 1 nxt[prv[i]] = nxt[i] prv[nxt[i]] = prv[i] i = prv[i] j = (j - 1) % M print(ans)