結果

問題 No.1373 Directed Operations
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2021-02-05 21:50:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 821 bytes
コンパイル時間 1,691 ms
コンパイル使用メモリ 173,492 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-15 08:01:25
合計ジャッジ時間 4,789 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 155 ms
4,376 KB
testcase_03 AC 19 ms
4,380 KB
testcase_04 AC 31 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 171 ms
4,376 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 20 ms
4,380 KB
testcase_09 AC 35 ms
4,376 KB
testcase_10 AC 30 ms
4,376 KB
testcase_11 AC 8 ms
4,380 KB
testcase_12 AC 30 ms
4,380 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 172 ms
4,376 KB
testcase_15 AC 151 ms
4,376 KB
testcase_16 AC 175 ms
4,380 KB
testcase_17 AC 120 ms
4,376 KB
testcase_18 AC 69 ms
4,380 KB
testcase_19 AC 70 ms
4,380 KB
testcase_20 AC 96 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2021.02.05 21:50:48
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    int n;cin >> n;
    vector<pair<int,int>> a(n-1);
    for (int i = 0; i < n-1; i++) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < n-1; i++) {
        if (i+2 <= a[i].first) {
            puts("NO");
            return 0;
        }
        a[i].first = i+2-a[i].first;
    }
    sort(a.begin(), a.end(), [](pair<int,int> a,pair<int,int> b) {
        if (a.second != b.second) {
            return a.second < b.second;
        }
        return a.first < b.first;
    });
    puts("YES");
    for (int i = 0; i < n-1; i++) {
        cout << a[i].first << endl;
    }
    return 0;
}
0