結果

問題 No.332 数列をプレゼントに
ユーザー PachicobuePachicobue
提出日時 2017-11-07 23:16:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,794 bytes
コンパイル時間 1,661 ms
コンパイル使用メモリ 176,596 KB
実行使用メモリ 402,924 KB
最終ジャッジ日時 2023-08-25 23:05:41
合計ジャッジ時間 5,539 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 59 ms
61,464 KB
testcase_06 AC 55 ms
59,336 KB
testcase_07 AC 73 ms
75,812 KB
testcase_08 AC 94 ms
98,688 KB
testcase_09 AC 4 ms
5,232 KB
testcase_10 AC 10 ms
11,412 KB
testcase_11 AC 43 ms
46,608 KB
testcase_12 AC 35 ms
37,416 KB
testcase_13 AC 43 ms
46,296 KB
testcase_14 AC 47 ms
49,036 KB
testcase_15 AC 10 ms
11,568 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 162 ms
181,508 KB
testcase_19 AC 25 ms
5,212 KB
testcase_20 AC 16 ms
17,304 KB
testcase_21 AC 5 ms
6,920 KB
testcase_22 AC 11 ms
12,624 KB
testcase_23 AC 48 ms
50,384 KB
testcase_24 AC 47 ms
50,352 KB
testcase_25 AC 47 ms
50,364 KB
testcase_26 AC 46 ms
49,952 KB
testcase_27 AC 46 ms
50,004 KB
testcase_28 AC 47 ms
50,020 KB
testcase_29 AC 47 ms
50,352 KB
testcase_30 AC 45 ms
49,960 KB
testcase_31 AC 46 ms
50,356 KB
testcase_32 AC 46 ms
50,008 KB
testcase_33 AC 7 ms
4,376 KB
testcase_34 AC 22 ms
5,120 KB
testcase_35 MLE -
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 3 ms
4,384 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 90 ms
94,284 KB
testcase_46 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    ll X;
    cin >> X;
    constexpr ll LEVEL = 100000;
    using P = pair<ll, int>;
    vector<P> lower;
    vector<P> upper;
    ll lower_sum = 0;
    for (int i = 0; i < N; i++) {
        ll v;
        cin >> v;
        lower_sum += ((v >= LEVEL) ? 0 : v);
        ((v >= LEVEL) ? upper : lower).push_back(make_pair(v, i));
    }

    const int upper_size = upper.size();
    const int maximum = 1 << upper_size;
    vector<ll> upper_sum(maximum, 0);
    for (int i = 0; i < maximum; i++) {
        for (int j = 0; j < upper_size; j++) {
            if (i & (1 << j)) {
                upper_sum[i] += upper[j].first;
            }
            if (upper_sum[i] > X) {
                upper_sum[i] = -1;
            }
        }
    }

    const int lower_size = lower.size();
    vector<vector<int>> dp(lower_size + 1, vector<int>(lower_sum + 1, -2));
    dp[0][0] = -1;
    for (int i = 0; i < lower_size; i++) {
        for (int j = 0; j <= lower_sum; j++) {
            if (dp[i][j] != -2) {
                dp[i + 1][j] = max(dp[i + 1][j], -1);
                dp[i + 1][j + lower[i].first] = i;
            }
        }
    }
    for (int i = 0; i < maximum; i++) {
        if (X < upper_sum[i] or upper_sum[i] < 0) {
            continue;
        }
        ll rest = X - upper_sum[i];
        if (rest > lower_sum) {
            continue;
        }

        if (dp[lower_size][rest] != -2) {
            vector<bool> use(N, false);
            for (int j = 0; j < upper_size; j++) {
                if (i & (1 << j)) {
                    use[upper[j].second] = true;
                }
            }
            for (int j = lower_size; j >= 1; j--) {
                if (dp[j][rest] != -1) {
                    use[lower[dp[j][rest]].second] = true;
                    rest -= lower[dp[j][rest]].first;
                }
            }
            for (int j = 0; j < N; j++) {
                cout << (use[j] ? 'o' : 'x');
            }
            cout << "\n";
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}
0