結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 14 ms
19,196 KB
testcase_02 WA -
testcase_03 AC 10 ms
19,024 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 416 ms
20,216 KB
testcase_08 WA -
testcase_09 AC 22 ms
19,024 KB
testcase_10 AC 145 ms
19,972 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1,222 ms
21,008 KB
testcase_25 AC 879 ms
20,464 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 531 ms
20,088 KB
testcase_29 AC 466 ms
19,996 KB
testcase_30 WA -
testcase_31 AC 466 ms
19,956 KB
testcase_32 AC 493 ms
20,356 KB
testcase_33 AC 186 ms
19,124 KB
testcase_34 AC 214 ms
19,072 KB
testcase_35 AC 319 ms
19,228 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 203 ms
19,080 KB
testcase_39 WA -
testcase_40 AC 219 ms
19,184 KB
testcase_41 AC 216 ms
19,016 KB
testcase_42 AC 214 ms
19,140 KB
testcase_43 AC 214 ms
19,104 KB
testcase_44 WA -
testcase_45 AC 212 ms
19,228 KB
testcase_46 AC 103 ms
19,076 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";
                    } else
                        cout << "x";
                }
                if (cnt != x) {
                    rep(k, n)
                    {
                        if (!flag[k] && cnt + a[i] == cnt) {
                            flag[k] = true;break;
                        }
                    }
                }
                rep(k, n)
                {
                    if (flag[k]) {
                        cout << "o";
                    } else
                        cout << "x";
                }
                cout << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}
0