結果

問題 No.3086 Re One Two
ユーザー SPD_9X2
提出日時 2025-04-06 05:46:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 433 ms / 2,000 ms
コード長 601 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 273,056 KB
最終ジャッジ日時 2025-04-06 05:46:59
合計ジャッジ時間 9,331 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

https://yukicoder.me/problems/no/3086

"""

import sys
from sys import stdin

sys.setrecursionlimit(3*(10**5))

N = int(stdin.readline())

A = []
B = []

for i in range(N):
    a,b = map(int,stdin.readline().split())
    A.append(a)
    B.append(b)


re = {}

two = []

ans = []

def put(i):
    ans.append(i+1)
    if i in re:
        put(re[i])

for i in range(N):

    if A[i] == 1:
        re[i+1] = i

    if B[i] == 2:
        two.append(i)

    if B[i] == 1:
        re[i] = two[-1]

rev = set( re.values() )

for i in range(N):
    if i not in rev:
        put(i)

print (*ans,sep="\n")
0