結果

問題 No.1373 Directed Operations
ユーザー gew1fw
提出日時 2025-06-12 14:11:31
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 730 bytes
コンパイル時間 462 ms
コンパイル使用メモリ 82,184 KB
実行使用メモリ 107,660 KB
最終ジャッジ日時 2025-06-12 14:12:10
合計ジャッジ時間 4,972 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 1 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

n = int(input())
a = list(map(int, input().split()))

reachable = [False] * (n + 1)
reachable[1] = True

unreachable = list(range(2, n + 1))
heapq.heapify(unreachable)

result = []
possible = True

for ai in a:
    temp = []
    found = False
    while unreachable:
        s = heapq.heappop(unreachable)
        x = s - ai
        if x >= 1 and reachable[x]:
            reachable[s] = True
            result.append(x)
            found = True
            break
        else:
            temp.append(s)
    if not found:
        possible = False
        break
    for node in temp:
        heapq.heappush(unreachable, node)

if possible:
    print("YES")
    for x in result:
        print(x)
else:
    print("NO")
0