結果

問題 No.1373 Directed Operations
ユーザー wotsushiwotsushi
提出日時 2020-11-04 22:09:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 577 bytes
コンパイル時間 2,092 ms
コンパイル使用メモリ 205,956 KB
実行使用メモリ 8,048 KB
最終ジャッジ日時 2023-09-29 16:21:13
合計ジャッジ時間 5,686 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 179 ms
8,028 KB
testcase_03 AC 51 ms
7,980 KB
testcase_04 AC 27 ms
8,048 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 227 ms
8,036 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 23 ms
4,376 KB
testcase_09 AC 99 ms
8,028 KB
testcase_10 AC 82 ms
7,316 KB
testcase_11 AC 18 ms
4,416 KB
testcase_12 AC 64 ms
7,136 KB
testcase_13 AC 8 ms
4,376 KB
testcase_14 AC 208 ms
7,948 KB
testcase_15 AC 179 ms
7,716 KB
testcase_16 AC 207 ms
7,936 KB
testcase_17 AC 136 ms
6,804 KB
testcase_18 AC 79 ms
5,388 KB
testcase_19 AC 85 ms
5,196 KB
testcase_20 AC 122 ms
5,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

// 各操作を先読みしない解法
// 各操作で選ぶxをなるべく小さくする貪欲法

int main() {
  int N;
  cin >> N;
  set<int> S;
  for (int i = 2; i <= N; ++i) {
    S.insert(i);
  }
  vector<int> x(N);
  for (int i = 1; i <= N - 1; ++i) {
    int a;
    cin >> a;
    auto j = S.lower_bound(a + 1);
    if (j == S.end()) {
      cout << "NO" << endl;
      return 0;
    }
    x[i] = *j - a;
    S.erase(*j);
  }
  cout << "YES" << endl;
  for (int i = 1; i <= N - 1; ++i) {
    cout << x[i] << endl;
  }
}
0