結果
| 問題 |
No.1888 Odd Insertion
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-31 18:01:42 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,733 bytes |
| コンパイル時間 | 187 ms |
| コンパイル使用メモリ | 82,612 KB |
| 実行使用メモリ | 147,372 KB |
| 最終ジャッジ日時 | 2025-03-31 18:02:29 |
| 合計ジャッジ時間 | 10,784 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 14 WA * 10 TLE * 1 -- * 12 |
ソースコード
import bisect
def solve():
import sys
input = sys.stdin.read
data = input().split()
N = int(data[0])
P = list(map(int, data[1:N+1]))
S = [] # Maintained as a sorted list
result = []
current_array = P.copy()
for i in range(N, 0, -1):
possible_js = list(range(1, i + 1, 2)) # Generate 1, 3, 5,... <= i
# Try positions in reverse order to avoid shifting issues
possible_js.sort(reverse=True)
found = False
for j in possible_js:
pos = j - 1 # Convert to 0-based index
if pos >= len(current_array):
continue # Skip if position is beyond current array's length
candidate = current_array[pos]
# Check if candidate is valid (min or second min in S + candidate)
valid = False
if not S:
valid = True
else:
if len(S) == 1:
valid = True
else:
# S is sorted, so check if candidate <= S[1]
if candidate <= S[1]:
valid = True
if valid:
# Remove from current array
current_array.pop(pos)
# Add to S in sorted order
bisect.insort(S, candidate)
# Append to result (will be reversed later)
result.append((candidate, j))
found = True
break
if not found:
print("No")
return
# Reverse the result to get the correct order
result.reverse()
print("Yes")
for x, y in result:
print(x, y)
solve()
lam6er