結果

問題 No.1373 Directed Operations
コンテスト
ユーザー kcvlex
提出日時 2021-02-12 19:23:35
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 834 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 737 ms
コンパイル使用メモリ 98,408 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-17 19:43:46
合計ジャッジ時間 2,476 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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