結果

問題 No.332 数列をプレゼントに
ユーザー PachicobuePachicobue
提出日時 2017-11-07 22:58:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,666 bytes
コンパイル時間 1,535 ms
コンパイル使用メモリ 179,484 KB
実行使用メモリ 403,200 KB
最終ジャッジ日時 2024-05-03 07:00:47
合計ジャッジ時間 5,176 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 53 ms
61,568 KB
testcase_06 AC 49 ms
59,520 KB
testcase_07 AC 64 ms
76,160 KB
testcase_08 AC 86 ms
98,816 KB
testcase_09 AC 3 ms
6,944 KB
testcase_10 AC 9 ms
11,648 KB
testcase_11 AC 38 ms
46,720 KB
testcase_12 AC 32 ms
37,504 KB
testcase_13 AC 39 ms
46,336 KB
testcase_14 AC 43 ms
49,152 KB
testcase_15 AC 10 ms
11,648 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 WA -
testcase_18 AC 154 ms
181,632 KB
testcase_19 WA -
testcase_20 AC 16 ms
17,536 KB
testcase_21 AC 6 ms
7,296 KB
testcase_22 AC 9 ms
12,928 KB
testcase_23 WA -
testcase_24 AC 43 ms
50,304 KB
testcase_25 AC 42 ms
50,432 KB
testcase_26 WA -
testcase_27 AC 42 ms
50,176 KB
testcase_28 AC 41 ms
50,304 KB
testcase_29 AC 42 ms
50,176 KB
testcase_30 WA -
testcase_31 AC 41 ms
50,304 KB
testcase_32 AC 41 ms
50,304 KB
testcase_33 AC 6 ms
6,944 KB
testcase_34 AC 18 ms
6,944 KB
testcase_35 MLE -
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 2 ms
6,944 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 1 ms
6,940 KB
testcase_40 AC 2 ms
6,948 KB
testcase_41 AC 2 ms
6,944 KB
testcase_42 AC 1 ms
6,940 KB
testcase_43 AC 2 ms
6,944 KB
testcase_44 AC 2 ms
6,940 KB
testcase_45 AC 83 ms
94,464 KB
testcase_46 AC 2 ms
6,944 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;
            }
        }
    }

    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] = -1;
                dp[i + 1][j + lower[i].first] = i;
            }
        }
    }
    for (int i = 0; i < maximum; i++) {
        if (X < upper_sum[i]) {
            break;
        }
        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