結果

問題 No.332 数列をプレゼントに
ユーザー kyo1kyo1
提出日時 2020-06-21 08:15:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,400 bytes
コンパイル時間 2,113 ms
コンパイル使用メモリ 206,992 KB
実行使用メモリ 29,880 KB
最終ジャッジ日時 2023-09-16 18:06:45
合計ジャッジ時間 10,412 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 10 ms
14,708 KB
testcase_02 WA -
testcase_03 AC 8 ms
14,652 KB
testcase_04 AC 5 ms
14,788 KB
testcase_05 WA -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 OLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

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>> A(N);
  for (int i = 0; i < N; i++) {
    int64_t a;
    cin >> a;
    A[i] = make_pair(a, i);
  }
  sort(A.begin(), A.end());
  vector<int> dp(3000000, -1);
  dp[0] = 0;
  int pos = 0;
  int64_t sum = 0;
  for (int i = 0; i < N; i++) {
    if (sum + A[i].first > 2000000) {
      pos = i;
      break;
    }
    for (int j = 2000000; j > -1; j--) {
      if ((j == 0 || dp[j] != -1) && dp[j + A[i].first] == -1) {
        dp[j + A[i].first] = A[i].second;
      }
    }
    sum += A[i].first;
    pos = i + 1;
  }
  for (int bit = 0; bit < (1 << (N - pos + 1)); bit++) {
    sum = 0;
    for (int i = 0; i < N - pos; i++) {
      if ((bit >> i) & 1) {
        sum += A[i + pos].first;
      }
    }
    sum = X - sum;
    if (sum == 0 || (sum < 3000000 && dp[sum] != -1)) {
      vector<char> res(N, 'x');
      for (int i = 0; i < N - pos; i++) {
        if ((bit >> i) & 1) {
          res[A[i + pos].second] = 'o';
        }
      }
      while (sum != 0) {
        cout << dp[sum] << '\n';
        res[A[dp[sum]].second] = 'o';
        sum -= A[dp[sum]].first;
      }
      for (int i = 0; i < N; i++) {
        cout << res[i];
      }
      cout << '\n';
      return 0;
    }
  }
  cout << "No" << '\n';
  return 0;
}
0