結果

問題 No.1373 Directed Operations
ユーザー gew1fw
提出日時 2025-06-12 21:36:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,042 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 81,872 KB
実行使用メモリ 114,864 KB
最終ジャッジ日時 2025-06-12 21:38:50
合計ジャッジ時間 3,517 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx])
    idx += 1
    a = list(map(int, input[idx:idx + N - 1]))
    idx += N - 1

    R = {1}
    current_max = 1
    res = []
    possible = True

    for ai in a:
        if (1 + ai) not in R:
            x = 1
            res.append(x)
            new_node = x + ai
            R.add(new_node)
            if new_node > current_max:
                current_max = new_node
        else:
            x = current_max - ai + 1
            if x < 1 or x > (N - ai):
                possible = False
                break
            if x not in R or (x + ai) in R:
                possible = False
                break
            res.append(x)
            new_node = x + ai
            R.add(new_node)
            if new_node > current_max:
                current_max = new_node

    if possible and len(R) == N:
        print("YES")
        for x in res:
            print(x)
    else:
        print("NO")

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