結果

問題 No.332 数列をプレゼントに
ユーザー kyo1kyo1
提出日時 2020-06-18 02:05:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,363 bytes
コンパイル時間 2,109 ms
コンパイル使用メモリ 207,480 KB
実行使用メモリ 6,356 KB
最終ジャッジ日時 2023-09-16 11:53:00
合計ジャッジ時間 4,598 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,144 KB
testcase_01 AC 3 ms
6,052 KB
testcase_02 AC 3 ms
6,168 KB
testcase_03 AC 2 ms
6,156 KB
testcase_04 AC 3 ms
6,116 KB
testcase_05 AC 4 ms
6,172 KB
testcase_06 AC 3 ms
6,076 KB
testcase_07 AC 4 ms
6,212 KB
testcase_08 AC 3 ms
6,132 KB
testcase_09 AC 3 ms
6,080 KB
testcase_10 AC 3 ms
6,132 KB
testcase_11 AC 3 ms
6,144 KB
testcase_12 AC 3 ms
6,156 KB
testcase_13 AC 3 ms
6,224 KB
testcase_14 AC 4 ms
6,200 KB
testcase_15 AC 3 ms
6,072 KB
testcase_16 AC 4 ms
6,264 KB
testcase_17 AC 3 ms
6,196 KB
testcase_18 AC 4 ms
6,204 KB
testcase_19 AC 4 ms
6,072 KB
testcase_20 AC 3 ms
6,220 KB
testcase_21 AC 4 ms
6,292 KB
testcase_22 AC 4 ms
6,072 KB
testcase_23 AC 4 ms
6,136 KB
testcase_24 AC 4 ms
6,188 KB
testcase_25 AC 3 ms
6,136 KB
testcase_26 AC 3 ms
6,224 KB
testcase_27 AC 3 ms
6,152 KB
testcase_28 AC 3 ms
6,080 KB
testcase_29 AC 3 ms
6,072 KB
testcase_30 AC 3 ms
6,144 KB
testcase_31 AC 3 ms
6,140 KB
testcase_32 AC 3 ms
6,132 KB
testcase_33 AC 7 ms
6,136 KB
testcase_34 AC 20 ms
6,204 KB
testcase_35 AC 34 ms
6,120 KB
testcase_36 AC 4 ms
6,204 KB
testcase_37 AC 3 ms
6,128 KB
testcase_38 AC 3 ms
6,348 KB
testcase_39 AC 3 ms
6,228 KB
testcase_40 AC 4 ms
6,200 KB
testcase_41 AC 4 ms
6,180 KB
testcase_42 AC 4 ms
6,288 KB
testcase_43 AC 3 ms
6,136 KB
testcase_44 AC 4 ms
6,132 KB
testcase_45 AC 4 ms
6,356 KB
testcase_46 AC 3 ms
6,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  int64_t X;
  cin >> N >> X;
  vector<pair<int64_t, int>> P(N);
  for (int i = 0; i < N; i++) {
    int64_t a;
    cin >> a;
    P[i] = make_pair(a, i);
  }
  sort(P.begin(), P.end());
  int64_t sum = 0, bound = 200000;
  vector<int64_t> dp(bound * 2, -1);
  dp[0] = 0;
  int base = 0;
  for (int i = 0; i < N; i++) {
    if (sum + P[i].first > bound) {
      base = i;
      break;
    }
    for (int j = sum; j > -1; j--) {
      if (dp[j] >= 0 && dp[j + P[i].first] == -1) {
        dp[j + P[i].first] = i;
      }
    }
    sum += P[i].first;
  }
  if (sum + P.back().first <= bound) base++;
  vector<char> res(N, 'x');
  for (int b = 0; b < (1 << (N - base)); b++) {
    int64_t t = 0;
    for (int i = 0; i < N - base; i++) {
      if ((b >> i) & 1) t += P[i + base].first;
    }
    if (X - t < 0 || X - t > bound) continue;
    if (dp[X - t] >= 0) {
      for (int i = 0; i < N - base; i++) {
        if ((b >> i) & 1) {
          res[P[i + base].second] = 'o';
        }
      }
      int64_t x = X - t;
      while (x > 0) {
        res[P[dp[x]].second] = 'o';
        x -= P[dp[x]].first;
      }
      for (auto &v : res) {
        cout << v;
      }
      cout << '\n';
      return 0;
    }
  }
  cout << "No" << '\n';
  return 0;
}
0