結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
18,928 KB
testcase_01 AC 15 ms
18,988 KB
testcase_02 AC 11 ms
18,984 KB
testcase_03 AC 10 ms
19,052 KB
testcase_04 AC 11 ms
19,052 KB
testcase_05 AC 149 ms
23,628 KB
testcase_06 WA -
testcase_07 AC 434 ms
20,024 KB
testcase_08 AC 145 ms
20,908 KB
testcase_09 AC 21 ms
18,960 KB
testcase_10 AC 143 ms
19,996 KB
testcase_11 AC 128 ms
22,672 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 100 ms
21,644 KB
testcase_15 AC 192 ms
19,252 KB
testcase_16 AC 160 ms
19,092 KB
testcase_17 AC 174 ms
19,256 KB
testcase_18 WA -
testcase_19 AC 177 ms
19,144 KB
testcase_20 AC 180 ms
19,164 KB
testcase_21 AC 194 ms
19,244 KB
testcase_22 AC 172 ms
19,240 KB
testcase_23 AC 473 ms
20,416 KB
testcase_24 AC 1,234 ms
20,812 KB
testcase_25 AC 873 ms
20,536 KB
testcase_26 AC 694 ms
20,736 KB
testcase_27 AC 190 ms
20,600 KB
testcase_28 AC 513 ms
20,160 KB
testcase_29 AC 452 ms
19,956 KB
testcase_30 AC 252 ms
20,084 KB
testcase_31 AC 449 ms
19,968 KB
testcase_32 AC 478 ms
20,008 KB
testcase_33 AC 187 ms
19,064 KB
testcase_34 AC 195 ms
19,068 KB
testcase_35 AC 317 ms
19,096 KB
testcase_36 AC 11 ms
18,988 KB
testcase_37 WA -
testcase_38 AC 183 ms
19,100 KB
testcase_39 AC 185 ms
18,996 KB
testcase_40 AC 195 ms
18,940 KB
testcase_41 AC 195 ms
19,084 KB
testcase_42 AC 199 ms
19,228 KB
testcase_43 AC 204 ms
19,276 KB
testcase_44 AC 205 ms
19,112 KB
testcase_45 AC 203 ms
19,296 KB
testcase_46 AC 95 ms
19,092 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 = 2000005;
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] > 20000) {
            big.push_back(a[i]);
            bigm.push_back(i);
        } else {
            small.push_back(a[i]);
            smallm.push_back(i);
        }
    }
    rep(i, M) dp[i] = make_pair(false, -1);
    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 (lli i = 0; i < (1 << big.size()); i++) {
        lli 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;
                    }
                }
                lli cnt = dp[i].second;
                if (i > 0) {
                    while (1) {
                        flag[smallm[cnt]] = true;
                        if (i <= 0)
                            break;
                        i -= small[dp[i].second];
                        cnt = dp[i].second;
                        if (cnt < 0)
                            break;
                    }
                }
                cnt = 0;
                rep(k, n)
                {
                    if (flag[k]) {
                        cout << "o";
                        cnt += a[k];
                    } else
                        cout << "x";
                }
               // cout << cnt << endl;
                cout << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}
0