結果

問題 No.332 数列をプレゼントに
ユーザー uenokuuenoku
提出日時 2017-02-10 00:47:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,400 bytes
コンパイル時間 1,024 ms
コンパイル使用メモリ 96,968 KB
実行使用メモリ 23,208 KB
最終ジャッジ日時 2023-08-26 22:59:48
合計ジャッジ時間 13,251 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,376 KB
testcase_01 AC 5 ms
4,376 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 4 ms
4,384 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 133 ms
18,000 KB
testcase_06 WA -
testcase_07 AC 481 ms
15,552 KB
testcase_08 AC 178 ms
23,208 KB
testcase_09 AC 9 ms
4,376 KB
testcase_10 AC 128 ms
4,968 KB
testcase_11 AC 109 ms
14,948 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 137 ms
20,712 KB
testcase_15 AC 71 ms
4,376 KB
testcase_16 AC 66 ms
4,380 KB
testcase_17 AC 76 ms
4,376 KB
testcase_18 WA -
testcase_19 AC 97 ms
4,380 KB
testcase_20 AC 71 ms
4,376 KB
testcase_21 AC 78 ms
4,376 KB
testcase_22 AC 68 ms
4,500 KB
testcase_23 AC 526 ms
8,984 KB
testcase_24 AC 1,416 ms
10,620 KB
testcase_25 AC 1,105 ms
9,104 KB
testcase_26 AC 711 ms
8,576 KB
testcase_27 AC 99 ms
8,560 KB
testcase_28 AC 574 ms
6,728 KB
testcase_29 AC 505 ms
6,492 KB
testcase_30 AC 184 ms
6,704 KB
testcase_31 AC 533 ms
6,492 KB
testcase_32 AC 516 ms
6,600 KB
testcase_33 AC 80 ms
4,376 KB
testcase_34 AC 104 ms
4,376 KB
testcase_35 AC 75 ms
4,376 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 WA -
testcase_38 AC 75 ms
4,376 KB
testcase_39 AC 75 ms
4,380 KB
testcase_40 AC 82 ms
4,380 KB
testcase_41 AC 83 ms
4,376 KB
testcase_42 AC 83 ms
4,380 KB
testcase_43 AC 82 ms
4,376 KB
testcase_44 AC 83 ms
4,380 KB
testcase_45 AC 83 ms
4,380 KB
testcase_46 AC 38 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
const int M = 1000005;
pair<bool, int> dp[M] = {};
int main()
{
    lli n, x;
    lli a[105], b[105];
    vector<lli> big, small, bigm, smallm;
    cin >> n >> x;
    rep(i, n)
    {
        cin >> a[i];
        if (a[i] > 100000) {
            big.push_back(a[i]);
            bigm.push_back(i);
        } else {
            small.push_back(a[i]);
            smallm.push_back(i);
        }
    }
    if (small.size() > 0) {
        dp[small[0]] = make_pair(true, 0);
    }
    for (int i = 1; i < small.size(); i++) {
        dp[small[i]] = make_pair(true, i);
        rrep(j, M)
        {
            if (dp[j].first && j + small[i] < M && !dp[j + small[i]].first)
                dp[j + small[i]] = make_pair(true, i);
        }
    }
    set<lli> l;
    rep(j, M) if (dp[j].first) l.insert(j);
    map<lli, lli> memo;
    set<lli> s;
    for (int i = 0; i < (1 << big.size()); i++) {
        int temp = i;
        lli sum = 0;
        rep(j, big.size())
        {
            if ((temp >> j) & 1)
                sum += big[j];
        }
        //cout << sum << endl;
        memo[sum] = i;
        s.insert(sum);
    }
    s.insert(0);
    l.insert(0);
    for (auto j : s) {
        for (auto i : l) {
            if (j + i == x) {
                //cout << i << endl;
                lli re = memo[j];
                bool flag[105] = {};
                rep(k, big.size())
                {
                    if ((re >> k) & 1) {
                        flag[bigm[k]] = true;
                    }
                }
                int cnt = dp[i].second;
                while (1 && i) {
                    flag[smallm[cnt]] = true;
                    i -= small[dp[i].second];
                    cnt = dp[i].second;
                }
                rep(i, n)
                {
                    if (flag[i]) {
                        cout << "o";
                       // cout << a[i] << endl;
                    } else
                        cout << "x";
                }
                cout << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}
0