結果

問題 No.1373 Directed Operations
ユーザー kcvlex
提出日時 2021-02-12 19:23:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 834 bytes
コンパイル時間 1,278 ms
コンパイル使用メモリ 78,912 KB
最終ジャッジ日時 2025-01-18 17:51:16
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

int main() {
    int n;
    std::cin >> n;
    std::vector<int> v(n - 1);
    for (int &e : v) std::cin >> e;
    std::vector<int> ord(n - 1);
    std::iota(std::begin(ord), std::end(ord), 0);
    std::sort(std::begin(ord), std::end(ord),
              [&](const int i, const int j) { return v[i] < v[j]; });
    int ub = 1;
    bool yes = true;
    std::vector<int> ans(n - 1);
    for (const int idx : ord) {
        const int d = v[idx];
        if (ub < d) {
            yes = false;
            break;
        }
        ans[idx] = ub - d + 1;
        ub++;
    }
    
    if (yes) {
        std::cout << "YES\n";
        for (int e : ans) {
            std::cout << e << "\n";
        }
    } else {
        std::cout << "NO\n";
    }
    return 0;
}
0