結果

問題 No.332 数列をプレゼントに
ユーザー uenokuuenoku
提出日時 2017-03-28 17:17:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,556 bytes
コンパイル時間 950 ms
コンパイル使用メモリ 94,560 KB
実行使用メモリ 585,204 KB
最終ジャッジ日時 2023-09-20 18:32:16
合計ジャッジ時間 33,947 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
23,888 KB
testcase_01 AC 31 ms
19,788 KB
testcase_02 AC 10 ms
9,492 KB
testcase_03 AC 16 ms
9,584 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 MLE -
testcase_06 MLE -
testcase_07 MLE -
testcase_08 MLE -
testcase_09 AC 54 ms
34,088 KB
testcase_10 AC 129 ms
80,552 KB
testcase_11 WA -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 WA -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 MLE -
testcase_23 MLE -
testcase_24 MLE -
testcase_25 MLE -
testcase_26 MLE -
testcase_27 MLE -
testcase_28 MLE -
testcase_29 MLE -
testcase_30 MLE -
testcase_31 MLE -
testcase_32 MLE -
testcase_33 MLE -
testcase_34 MLE -
testcase_35 MLE -
testcase_36 AC 1 ms
4,376 KB
testcase_37 MLE -
testcase_38 MLE -
testcase_39 MLE -
testcase_40 MLE -
testcase_41 MLE -
testcase_42 MLE -
testcase_43 MLE -
testcase_44 MLE -
testcase_45 MLE -
testcase_46 AC 335 ms
214,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (long long int i = 0; i < (n); i++)
#define rrep(i, n) for (long long int i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
struct node {
    lli sum = 0;
    lli mask = 0;
};
bool can[101][5000005] = {};
int main()

{
    lli n, x;
    cin >> n >> x;
    lli k = x;
    vector<lli> small, big;
    lli a[105];
    rep(i, n)
    {
        cin >> a[i];
        if (a[i] > 5 * 1e4)
            big.push_back(a[i]);
        else
            small.push_back(a[i]);
    }
    int nb = big.size();
    vector<node> data;
    map<lli, lli> m;

    rep(i, (1 << nb))
    {
        node tmp;
        tmp.mask = i;
        rep(j, nb)
        {
            if ((i >> j) & 1) {
                tmp.sum += big[j];
            }
        }
        // cout << tmp.sum << " " << tmp.mask << endl;
        // cout << i << endl;
        m[tmp.sum] = i;
        //cout << m[1e10] << endl;
    }

    m[0] = 1;
    int ns = small.size();
    can[0][0] = true;
    rep(i, ns)
    {
        rep(j, 5 * 1e6)
        {
            can[i + 1][j] |= can[i][j];
            if (can[i][j] && j + a[i] < 5 * 1e6) {
                can[i + 1][j + a[i]] = true;
            }
        }
    }
    //cout << m[1e10] << endl;

    rep(j, 5 * 1e6)
    {
        if (can[ns][j]) {
            if (m[k - j]) {
                //cout << "#k-j=" << k - j << endl;
                lli mask = m[k - j];
                //cout << m[k - j] << endl;
                if (k == j) {
                    mask = 0;
                }
                ///cout << mask << endl;
                map<lli, lli> cntUse;
                rep(l, nb)
                {
                    if ((mask >> l) & 1) {
                        cntUse[big[l]]++;
                    }
                }
                rrep(l, ns + 1)
                {
                    if (l == 0)
                        continue;
                    if (j - a[l - 1] >= 0 && can[l - 1][j - a[l - 1]]) {
                        cntUse[a[l - 1]]++;
                    }
                }
                string ans(n, 'x');
                rep(i, n)
                {
                    if (cntUse[a[i]] >= 0) {
                        ans[i] = 'o';
                        cntUse[a[i]]--;
                    }
                }
                cout << ans << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}
0