結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー qwewe
提出日時 2025-04-24 12:21:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 502 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 82,104 KB
実行使用メモリ 116,348 KB
最終ジャッジ日時 2025-04-24 12:23:54
合計ジャッジ時間 10,621 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27 WA * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int, input().split()))
elements = [(a[i], i + 1) for i in range(n)]  # (value, original 1-based index)
elements.sort(key=lambda x: (x[0], x[1]))  # stable sort by value, then by original index
pos = [e[1] for e in elements]

max_pos = n
count = 0

for i in range(n-1, -1, -1):
    current_pos = pos[i]
    if current_pos > max_pos:
        count += 1
        max_pos = current_pos
    else:
        if current_pos < max_pos:
            max_pos = current_pos

print(count)
0