結果

問題 No.332 数列をプレゼントに
ユーザー kimiyukikimiyuki
提出日時 2017-01-05 19:19:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 594 ms / 2,000 ms
コード長 1,500 bytes
コンパイル時間 1,096 ms
コンパイル使用メモリ 98,592 KB
実行使用メモリ 80,488 KB
最終ジャッジ日時 2023-08-25 22:10:33
合計ジャッジ時間 6,923 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 594 ms
66,852 KB
testcase_06 AC 208 ms
44,632 KB
testcase_07 AC 171 ms
35,960 KB
testcase_08 AC 510 ms
80,488 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 7 ms
4,976 KB
testcase_11 AC 269 ms
47,396 KB
testcase_12 AC 62 ms
18,488 KB
testcase_13 AC 37 ms
14,216 KB
testcase_14 AC 583 ms
74,516 KB
testcase_15 AC 22 ms
6,232 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 11 ms
5,180 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 17 ms
5,512 KB
testcase_21 AC 31 ms
7,052 KB
testcase_22 AC 19 ms
5,700 KB
testcase_23 AC 104 ms
40,660 KB
testcase_24 AC 101 ms
40,868 KB
testcase_25 AC 98 ms
40,896 KB
testcase_26 AC 101 ms
40,684 KB
testcase_27 AC 102 ms
40,568 KB
testcase_28 AC 46 ms
22,116 KB
testcase_29 AC 47 ms
22,204 KB
testcase_30 AC 45 ms
22,204 KB
testcase_31 AC 46 ms
22,268 KB
testcase_32 AC 47 ms
22,200 KB
testcase_33 AC 4 ms
4,380 KB
testcase_34 AC 10 ms
4,376 KB
testcase_35 AC 4 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 7 ms
4,376 KB
testcase_44 AC 4 ms
4,380 KB
testcase_45 AC 10 ms
5,324 KB
testcase_46 AC 9 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <functional>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)
typedef long long ll;
using namespace std;
int main() {
    int n; ll x; cin >> n >> x;
    vector<ll> a(n); repeat (i,n) cin >> a[i];
    vector<int> rank(n); whole(iota, rank, 0);
    whole(sort, rank, [&](int i, int j) { return a[i] < a[j]; });
    const ll limit = 1e5;
    unordered_map<int,vector<int> > low;
    low[0] = vector<int>();
    int i = 0;
    for (; i < n and a[rank[i]] < limit; ++ i) {
        unordered_map<int,vector<int> > prv = low;
        for (auto & it : prv) {
            it.second.push_back(rank[i]);
            low[it.first + a[rank[i]]] = it.second;
        }
    }
    vector<int> high; ll acc = 0;
    function<bool (int)> dfs = [&](int i) {
        if (i >= n) return false;
        if (dfs(i+1)) return true;
        acc += a[rank[i]];
        high.push_back(rank[i]);
        if (low.count(x - acc)) return true;
        if (dfs(i+1)) return true;
        high.pop_back();
        acc -= a[rank[i]];
        return false;
    };
    if (low.count(x) or dfs(i)) {
        string ans(n, 'x');
        for (int j : low[x - acc]) ans[j] = 'o';
        for (int j : high)         ans[j] = 'o';
        cout << ans << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}
0