結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 343 ms
65,300 KB
testcase_01 AC 240 ms
42,436 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 TLE -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

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);
        rep(j, M)
        {
            if (dp[j].first && j + small[i] < M)
                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;
                    if (i == 0)
                        break;
                    i -= small[dp[i].second];
                    cnt = dp[i].second;
                }
                // rev[i].push_back(-1);
                // rep(k, small.size())
                // {
                //     rep(t, 1e6)
                //     {
                //         trev[t] = rev[t];
                //     };
                //     rep(t, 1e6)
                //     {
                //         if (trev[t].size() > 0) {
                //             if (t - small[k] >= 0) {
                //                 if (rev[t - small[k]].size())
                //                     continue;
                //                 else {
                //                     rev[t - small[k]].clear();
                //                     rev[t - small[k]] = trev[t];
                //                     rev[t - small[k]].push_back(k);
                //                 }
                //             }
                //         }
                //     }
                // }
                // for (auto k : rev[0]) {
                //     if (k == -1)
                //         continue;
                //     //    cout << k << endl;
                //     flag[smallm[k]] = true;
                // }

                rep(i, n)
                {
                    if (flag[i])
                        cout << "o";
                    else
                        cout << "x";
                }
                cout << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}
0