結果

問題 No.332 数列をプレゼントに
ユーザー uenokuuenoku
提出日時 2017-02-10 00:55:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,468 bytes
コンパイル時間 1,018 ms
コンパイル使用メモリ 97,100 KB
実行使用メモリ 8,820 KB
最終ジャッジ日時 2023-08-26 23:00:07
合計ジャッジ時間 14,258 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,376 KB
testcase_01 AC 5 ms
4,380 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 RE -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 324 ms
4,652 KB
testcase_08 WA -
testcase_09 AC 8 ms
4,376 KB
testcase_10 AC 123 ms
4,720 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1,220 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 344 ms
5,056 KB
testcase_24 AC 1,089 ms
5,568 KB
testcase_25 AC 741 ms
5,368 KB
testcase_26 AC 574 ms
5,204 KB
testcase_27 WA -
testcase_28 AC 411 ms
4,808 KB
testcase_29 AC 335 ms
4,684 KB
testcase_30 WA -
testcase_31 AC 347 ms
4,660 KB
testcase_32 AC 377 ms
4,756 KB
testcase_33 AC 79 ms
4,380 KB
testcase_34 AC 103 ms
4,380 KB
testcase_35 AC 214 ms
4,380 KB
testcase_36 RE -
testcase_37 AC 80 ms
4,380 KB
testcase_38 AC 73 ms
4,376 KB
testcase_39 WA -
testcase_40 AC 83 ms
4,380 KB
testcase_41 AC 84 ms
4,376 KB
testcase_42 AC 84 ms
4,376 KB
testcase_43 AC 82 ms
4,376 KB
testcase_44 WA -
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] > 20000) {
            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) {
                    flag[smallm[cnt]] = true;
                    if (i == 0)
                        break;
                    i -= small[dp[i].second];
                    cnt = dp[i].second;
                }
                cnt = 0;
                rep(k, n)
                {
                    if (flag[k]) {
                        cout << "o";
                        cnt += a[k];
                    } else
                        cout << "x";
                }
              cout <<endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}
0