結果

問題 No.3086 Re One Two
コンテスト
ユーザー detteiuu
提出日時 2025-04-05 13:35:24
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 450 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 380 ms
コンパイル使用メモリ 95,460 KB
実行使用メモリ 153,216 KB
最終ジャッジ日時 2026-07-08 11:58:01
合計ジャッジ時間 9,455 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

nex = dict()
pre = -1
for i, (A, B) in enumerate(AB):
    if A == 1:
        nex[i+1] = i
    if B == 2:
        pre = i
    elif B == 1:
        nex[i] = pre

ans = []
for i, (A, B) in enumerate(AB):
    if A != 1 and B != 2:
        ans.append(i)
        now = i
        while now in nex:
            now = nex[now]
            ans.append(now)

for a in ans:
    print(a+1)
0