結果

問題 No.1373 Directed Operations
ユーザー leaf_1415leaf_1415
提出日時 2020-10-08 00:04:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 651 bytes
コンパイル時間 2,057 ms
コンパイル使用メモリ 66,520 KB
実行使用メモリ 4,960 KB
最終ジャッジ日時 2023-09-28 00:36:08
合計ジャッジ時間 6,159 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 145 ms
4,948 KB
testcase_03 AC 18 ms
4,608 KB
testcase_04 AC 31 ms
4,524 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 160 ms
4,904 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 18 ms
4,380 KB
testcase_09 AC 37 ms
4,900 KB
testcase_10 AC 31 ms
4,796 KB
testcase_11 AC 8 ms
4,380 KB
testcase_12 AC 29 ms
4,544 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 162 ms
4,872 KB
testcase_15 AC 142 ms
4,960 KB
testcase_16 AC 160 ms
4,912 KB
testcase_17 AC 113 ms
4,548 KB
testcase_18 AC 64 ms
4,380 KB
testcase_19 AC 65 ms
4,380 KB
testcase_20 AC 92 ms
4,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cassert>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;
typedef pair<int, int> P;

int n;
int a[100005];
P p[100005];
int ans[100005];

int main()
{
	cin >> n;
	assert(n >= 2 && n <= 100000);
	for(int i = 1; i <= n-1; i++){
		cin >> a[i];
		assert(a[i] >= 1 && a[i] <= n-1);
	}
	
	for(int i = 1; i <= n-1; i++) p[i] = P(a[i], i);
	sort(p+1, p+n);
	
	for(int i = 1; i <= n-1; i++){
		if(p[i].first > i){
			cout << "NO" << endl;
			return 0;
		}
		ans[p[i].second] = (i+1) - a[p[i].second];
	}
	
	cout << "YES" << endl;
	for(int i = 1; i <= n-1; i++) cout << ans[i] << endl;
	
	return 0;
}
0