結果

問題 No.332 数列をプレゼントに
ユーザー kyo1kyo1
提出日時 2020-06-18 02:03:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,353 bytes
コンパイル時間 2,312 ms
コンパイル使用メモリ 208,348 KB
実行使用メモリ 6,304 KB
最終ジャッジ日時 2023-09-16 11:52:55
合計ジャッジ時間 8,326 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,208 KB
testcase_01 AC 3 ms
6,140 KB
testcase_02 AC 3 ms
6,104 KB
testcase_03 AC 3 ms
6,048 KB
testcase_04 AC 3 ms
6,124 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 3 ms
6,208 KB
testcase_08 WA -
testcase_09 AC 4 ms
6,140 KB
testcase_10 AC 3 ms
6,100 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 4 ms
6,084 KB
testcase_25 AC 4 ms
6,140 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 3 ms
6,132 KB
testcase_29 AC 4 ms
6,260 KB
testcase_30 WA -
testcase_31 AC 3 ms
6,064 KB
testcase_32 AC 4 ms
6,248 KB
testcase_33 AC 6 ms
6,068 KB
testcase_34 AC 19 ms
6,068 KB
testcase_35 AC 35 ms
6,180 KB
testcase_36 AC 3 ms
6,284 KB
testcase_37 WA -
testcase_38 AC 4 ms
6,120 KB
testcase_39 WA -
testcase_40 AC 3 ms
6,132 KB
testcase_41 AC 3 ms
6,112 KB
testcase_42 AC 3 ms
6,152 KB
testcase_43 AC 3 ms
6,144 KB
testcase_44 WA -
testcase_45 AC 5 ms
6,200 KB
testcase_46 AC 3 ms
6,192 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[dp[x]] = 'o';
        x -= P[dp[x]].first;
      }
      for (auto &v : res) {
        cout << v;
      }
      cout << '\n';
      return 0;
    }
  }
  cout << "No" << '\n';
  return 0;
}
0