結果
問題 |
No.1888 Odd Insertion
|
ユーザー |
![]() |
提出日時 | 2025-06-12 13:12:40 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,936 bytes |
コンパイル時間 | 240 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 177,896 KB |
最終ジャッジ日時 | 2025-06-12 13:15:44 |
合計ジャッジ時間 | 15,129 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 13 WA * 10 TLE * 2 -- * 12 |
ソースコード
def main(): import sys input = sys.stdin.read().split() N = int(input[0]) P = list(map(int, input[1:N+1])) current_array = P.copy() removed = [] answer = [] min1 = None min2 = None for i in range(N, 0, -1): possible_positions = [] y = 1 while y <= i: possible_positions.append(y) y += 2 candidates = [] for y in possible_positions: if y - 1 < len(current_array): candidates.append(current_array[y - 1]) valid_candidates = [] for x in candidates: if not removed: valid_candidates.append(x) else: if min2 is None: if x <= min1: valid_candidates.append(x) else: if x <= min2: valid_candidates.append(x) if not valid_candidates: print("No") return best_x = None best_pos = None for y in reversed(possible_positions): if y - 1 >= len(current_array): continue x = current_array[y - 1] if x in valid_candidates: best_x = x best_pos = y break if best_x is None: print("No") return answer.append((best_x, best_pos)) current_array.pop(best_pos - 1) removed.append(best_x) removed_sorted = sorted(removed) if len(removed_sorted) >= 1: min1 = removed_sorted[0] else: min1 = None if len(removed_sorted) >= 2: min2 = removed_sorted[1] else: min2 = None answer.reverse() print("Yes") for x, y in answer: print(x, y) if __name__ == "__main__": main()