結果

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

ソースコード

diff #

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

connected = [False] * (N + 2)  # 1-based indexing
connected[1] = True
smallest_unconnected = 2
x_list = []
possible = True

for ai in a:
    k = smallest_unconnected
    found = False
    while k <= N:
        if not connected[k]:
            x = k - ai
            if x >= 1 and connected[x]:
                connected[k] = True
                x_list.append(x)
                # Update smallest_unconnected
                while smallest_unconnected <= N and connected[smallest_unconnected]:
                    smallest_unconnected += 1
                found = True
                break
            else:
                k += 1
        else:
            k += 1
    if not found:
        possible = False
        break

if possible and smallest_unconnected > N:
    print("YES")
    for x in x_list:
        print(x)
else:
    print("NO")
0