結果

問題 No.332 数列をプレゼントに
ユーザー milanis48663220milanis48663220
提出日時 2020-06-22 22:01:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 2,202 bytes
コンパイル時間 1,287 ms
コンパイル使用メモリ 109,744 KB
実行使用メモリ 37,672 KB
最終ジャッジ日時 2023-09-16 19:28:46
合計ジャッジ時間 5,241 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 185 ms
28,780 KB
testcase_06 AC 118 ms
23,808 KB
testcase_07 AC 87 ms
20,148 KB
testcase_08 AC 246 ms
37,672 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 5 ms
4,888 KB
testcase_11 AC 124 ms
23,748 KB
testcase_12 AC 38 ms
10,932 KB
testcase_13 AC 30 ms
9,740 KB
testcase_14 AC 201 ms
31,440 KB
testcase_15 AC 7 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 5 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 6 ms
4,384 KB
testcase_21 AC 10 ms
4,380 KB
testcase_22 AC 7 ms
4,380 KB
testcase_23 AC 39 ms
11,628 KB
testcase_24 AC 39 ms
11,740 KB
testcase_25 AC 37 ms
11,744 KB
testcase_26 AC 39 ms
11,604 KB
testcase_27 AC 39 ms
11,908 KB
testcase_28 AC 19 ms
7,788 KB
testcase_29 AC 18 ms
7,788 KB
testcase_30 AC 19 ms
7,728 KB
testcase_31 AC 19 ms
7,832 KB
testcase_32 AC 18 ms
7,796 KB
testcase_33 AC 7 ms
4,376 KB
testcase_34 AC 23 ms
4,380 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,384 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 3 ms
4,380 KB
testcase_44 AC 3 ms
4,380 KB
testcase_45 AC 4 ms
4,380 KB
testcase_46 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int A[100];
int N;
ll X;
vector<ll> large, small;
int th = 100000; 
set<ll> st, buf;
int pre[3000000];

map<ll, vector<int>> idx_map;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> X;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        if(A[i] >= th) large.push_back(A[i]);
        else small.push_back(A[i]);
        idx_map[A[i]].push_back(i);
    }
    buf.insert(0);
    st.insert(0);
    sort(small.begin(), small.end());
    for(int i = 0; i < small.size(); i++){
        int m = small[i];
        vector<int> v;
        for(int n : buf){
            st.insert(n+m);
            if(pre[n+m] == 0) pre[n+m] = n;
            v.push_back(n+m);
        }
        for(int n : v){
            buf.insert(n);
        }
    }
    int sz = large.size();
    for(int i = 0; i < (1<<sz); i++){
        ll sum = 0;
        for(int j = 0; j < sz; j++){
            int m = 1<<j;
            if(i&m){
                sum += large[j];
            }
        }
        if(st.count(X-sum) != 0){
            ll cur = X-sum;
            set<int> used_idx;
            while(cur != 0){
                int d = cur-pre[cur];
                // cout << d << ' ';
                int sz = idx_map[d].size();
                used_idx.insert(idx_map[d][sz-1]);
                idx_map[d].pop_back();
                cur = pre[cur];
            }
            for(int j = 0; j < sz; j++){
                int m = 1<<j;
                if(i&m){
                    int sz = idx_map[large[j]].size();
                    used_idx.insert(idx_map[large[j]][sz-1]);
                    idx_map[large[j]].pop_back();
                }
            }
            ll tot = 0;
            for(int j = 0; j < N; j++){
                if(used_idx.count(j) == 0) cout << 'x';
                else {
                    tot += A[j];
                    cout << 'o';
                }
            }
            cout << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}
0