結果

問題 No.1373 Directed Operations
ユーザー wotsushiwotsushi
提出日時 2020-11-04 22:09:13
言語 C++17
(gcc 12.2.0 + boost 1.81.0)
結果
AC  
実行時間 260 ms / 2,000 ms
コード長 577 bytes
コンパイル時間 2,215 ms
コンパイル使用メモリ 205,952 KB
実行使用メモリ 8,220 KB
最終ジャッジ日時 2023-07-08 15:01:14
合計ジャッジ時間 6,184 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 203 ms
8,052 KB
testcase_03 AC 49 ms
8,104 KB
testcase_04 AC 27 ms
8,048 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 260 ms
8,052 KB
testcase_07 AC 7 ms
4,368 KB
testcase_08 AC 26 ms
4,372 KB
testcase_09 AC 99 ms
8,048 KB
testcase_10 AC 85 ms
7,444 KB
testcase_11 AC 18 ms
4,372 KB
testcase_12 AC 67 ms
7,276 KB
testcase_13 AC 9 ms
4,372 KB
testcase_14 AC 240 ms
8,068 KB
testcase_15 AC 206 ms
7,568 KB
testcase_16 AC 239 ms
8,220 KB
testcase_17 AC 157 ms
7,052 KB
testcase_18 AC 91 ms
5,492 KB
testcase_19 AC 96 ms
5,408 KB
testcase_20 AC 139 ms
5,872 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