結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 13 ms
19,040 KB
testcase_02 WA -
testcase_03 AC 9 ms
19,212 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 403 ms
20,104 KB
testcase_08 WA -
testcase_09 AC 18 ms
19,016 KB
testcase_10 AC 128 ms
19,952 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,112 ms
20,772 KB
testcase_25 AC 844 ms
20,468 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 474 ms
20,064 KB
testcase_29 AC 393 ms
19,952 KB
testcase_30 WA -
testcase_31 AC 400 ms
19,932 KB
testcase_32 AC 431 ms
20,076 KB
testcase_33 AC 153 ms
19,320 KB
testcase_34 AC 179 ms
19,032 KB
testcase_35 AC 280 ms
19,108 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 153 ms
18,980 KB
testcase_39 WA -
testcase_40 AC 167 ms
18,952 KB
testcase_41 AC 175 ms
19,184 KB
testcase_42 AC 166 ms
19,056 KB
testcase_43 AC 165 ms
19,060 KB
testcase_44 WA -
testcase_45 AC 176 ms
19,208 KB
testcase_46 AC 83 ms
19,096 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] == x) {
                            flag[k] = true;break;
                        }
                    }
                }
                rep(k, n)
                {
                    if (flag[k]) {
                        cout << "o";
                    } else
                        cout << "x";
                }
                cout << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}
0