結果

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

ソースコード

diff #

import sys

def main():
    sys.setrecursionlimit(1 << 25)
    N = int(sys.stdin.readline())
    a_list = list(map(int, sys.stdin.readline().split()))
    if len(a_list) != N-1:
        print("NO")
        return
    
    reachable = {1}
    sorted_reachable = [1]
    x_choices = []
    
    for a in a_list:
        found = False
        for x in sorted_reachable:
            y = x + a
            if y > N:
                continue
            if y not in reachable:
                reachable.add(y)
                x_choices.append(x)
                # Insert y into sorted_reachable to keep it sorted
                left, right = 0, len(sorted_reachable)
                while left < right:
                    mid = (left + right) // 2
                    if sorted_reachable[mid] < y:
                        left = mid + 1
                    else:
                        right = mid
                sorted_reachable.insert(left, y)
                found = True
                break
        if not found:
            print("NO")
            return
    if len(reachable) == N:
        print("YES")
        for x in x_choices:
            print(x)
    else:
        print("NO")

if __name__ == "__main__":
    main()
0