結果

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

ソースコード

diff #

import bisect

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    
    n = int(data[0])
    a = list(map(int, data[1:n]))
    
    reachable = [1]
    current_max = 1
    target = 2
    x_list = []
    
    for ai in a:
        if target > n:
            break
        x_candidate = target - ai
        if x_candidate >= 1:
            idx = bisect.bisect_left(reachable, x_candidate)
            if idx < len(reachable) and reachable[idx] == x_candidate:
                x = x_candidate
                y = x + ai
                x_list.append(x)
                if y > current_max:
                    current_max = y
                if y not in reachable:
                    bisect.insort(reachable, y)
                while target <= n:
                    idx_target = bisect.bisect_left(reachable, target)
                    if idx_target < len(reachable) and reachable[idx_target] == target:
                        target += 1
                    else:
                        break
                continue
        x_max = min(current_max, n - ai)
        if x_max < 1:
            print("NO")
            return
        idx = bisect.bisect_right(reachable, x_max) - 1
        if idx < 0:
            print("NO")
            return
        x = reachable[idx]
        y = x + ai
        x_list.append(x)
        if y > current_max:
            current_max = y
        if y not in reachable:
            bisect.insort(reachable, y)
        if y >= target:
            while target <= n:
                idx_target = bisect.bisect_left(reachable, target)
                if idx_target < len(reachable) and reachable[idx_target] == target:
                    target += 1
                else:
                    break
    
    if target > n:
        print("YES")
        for x in x_list:
            print(x)
    else:
        print("NO")

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