結果
| 問題 |
No.2210 equence Squence Seuence
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-26 15:46:33 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 525 ms / 2,000 ms |
| コード長 | 1,135 bytes |
| コンパイル時間 | 301 ms |
| コンパイル使用メモリ | 82,284 KB |
| 実行使用メモリ | 117,744 KB |
| 最終ジャッジ日時 | 2025-03-26 15:47:20 |
| 合計ジャッジ時間 | 7,108 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
import sys
from functools import cmp_to_key
def main():
N, K = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))
next_diff = [-1] * N
next_diff[-1] = -1 # since there's no next element after last
for i in range(N-2, -1, -1):
if A[i] != A[i+1]:
next_diff[i] = i
else:
next_diff[i] = next_diff[i+1]
def compare(i, j):
if i == j:
return 0
if i > j:
return -compare(j, i)
# Now i < j
m = next_diff[i]
if m != -1 and m < j:
a = A[m+1]
b = A[m]
if a < b:
return -1
elif a > b:
return 1
else:
return 0
else:
# All elements from i to j-1 are same, compare indices
return -1 # since i < j, so X_i comes before X_j
indices = list(range(N))
indices.sort(key=cmp_to_key(compare))
selected = indices[K-1]
result = A[:selected] + A[selected+1:]
print(' '.join(map(str, result)))
if __name__ == "__main__":
main()
lam6er