結果

問題 No.1373 Directed Operations
ユーザー SSRSSSRS
提出日時 2021-02-05 21:24:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 638 bytes
コンパイル時間 1,745 ms
コンパイル使用メモリ 172,172 KB
実行使用メモリ 4,648 KB
最終ジャッジ日時 2023-09-15 07:06:31
合計ジャッジ時間 4,714 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 148 ms
4,592 KB
testcase_03 AC 20 ms
4,612 KB
testcase_04 AC 32 ms
4,648 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 164 ms
4,620 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 20 ms
4,380 KB
testcase_09 AC 38 ms
4,648 KB
testcase_10 AC 33 ms
4,480 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 32 ms
4,380 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 167 ms
4,620 KB
testcase_15 AC 144 ms
4,380 KB
testcase_16 AC 167 ms
4,568 KB
testcase_17 AC 117 ms
4,384 KB
testcase_18 AC 67 ms
4,376 KB
testcase_19 AC 67 ms
4,376 KB
testcase_20 AC 96 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> a(N - 1);
  for (int i = 0; i < N - 1; i++){
    cin >> a[i];
  }
  vector<pair<int, int>> P(N - 1);
  for (int i = 0; i < N - 1; i++){
    P[i] = make_pair(a[i], i);
  }
  sort(P.begin(), P.end());
  bool ok = true;
  vector<int> x(N - 1);
  for (int i = 0; i < N - 1; i++){
    if (P[i].first > i + 1){
      ok = false;
    } else {
      x[P[i].second] = i - P[i].first + 1;
    }
  }
  if (!ok){
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
    for (int i = 0; i < N - 1; i++){
      cout << x[i] + 1 << endl;
    }
  }
}
0