結果

問題 No.1373 Directed Operations
ユーザー FromBooskaFromBooska
提出日時 2023-02-23 09:53:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 508 ms / 2,000 ms
コード長 913 bytes
コンパイル時間 648 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 103,040 KB
最終ジャッジ日時 2024-07-23 07:21:33
合計ジャッジ時間 7,093 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

# おっと有向辺だった
# しかも1から全頂点にたどり着けるかという問題
# 完全に問題読み違えてた
# Union Findでもない
# 辺をソートして、1がなければ2にたどり着けない
# 2までたどり着いたら、1か2がなければ3にたどり着けない
# これを繰り返してNまで行ければYES
# グラフ構築では、行先から辺の数を引けば起点が決まる

N = int(input())
A = list(map(int, input().split()))
A_with_idx = []
for i in range(N-1):
    A_with_idx.append([A[i], i])
A_with_idx.sort()


ans = 'YES'
for i in range(1, N):
    if A_with_idx[i-1][0] > i:
        ans = 'NO'
        break
    else:
        A_with_idx[i-1].append(i+1-A_with_idx[i-1][0])
A_with_idx.sort(key = lambda x:x[1])
    
#print(ans)
#print(A_with_idx)

if ans == 'NO':
    print(ans)
else: 
    print(ans)
    for a, b, c in A_with_idx:
        print(c)
0