結果

問題 No.1373 Directed Operations
ユーザー kcvlexkcvlex
提出日時 2021-02-12 19:23:35
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 834 bytes
コンパイル時間 1,056 ms
コンパイル使用メモリ 80,436 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 00:09:00
合計ジャッジ時間 3,271 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 26 ms
4,384 KB
testcase_03 AC 17 ms
4,380 KB
testcase_04 AC 29 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 46 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 7 ms
4,380 KB
testcase_09 AC 37 ms
4,380 KB
testcase_10 AC 32 ms
4,384 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 31 ms
4,380 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 45 ms
4,380 KB
testcase_15 AC 40 ms
4,380 KB
testcase_16 AC 46 ms
4,384 KB
testcase_17 AC 21 ms
4,380 KB
testcase_18 AC 13 ms
4,380 KB
testcase_19 AC 19 ms
4,380 KB
testcase_20 AC 26 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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