結果

問題 No.332 数列をプレゼントに
ユーザー milanis48663220milanis48663220
提出日時 2020-06-22 21:53:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,095 bytes
コンパイル時間 1,135 ms
コンパイル使用メモリ 106,452 KB
実行使用メモリ 41,528 KB
最終ジャッジ日時 2023-09-16 19:28:52
合計ジャッジ時間 5,767 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,656 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,416 KB
testcase_03 AC 2 ms
5,384 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 197 ms
32,788 KB
testcase_06 AC 123 ms
27,776 KB
testcase_07 AC 99 ms
24,236 KB
testcase_08 AC 257 ms
41,528 KB
testcase_09 AC 3 ms
5,416 KB
testcase_10 AC 5 ms
6,748 KB
testcase_11 AC 137 ms
27,824 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 219 ms
35,572 KB
testcase_15 WA -
testcase_16 AC 2 ms
5,404 KB
testcase_17 AC 2 ms
5,424 KB
testcase_18 WA -
testcase_19 AC 2 ms
5,564 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 41 ms
13,716 KB
testcase_24 AC 41 ms
13,676 KB
testcase_25 AC 42 ms
13,852 KB
testcase_26 AC 42 ms
13,700 KB
testcase_27 AC 42 ms
13,784 KB
testcase_28 AC 19 ms
9,920 KB
testcase_29 AC 19 ms
9,932 KB
testcase_30 AC 19 ms
9,944 KB
testcase_31 AC 20 ms
9,856 KB
testcase_32 AC 20 ms
9,836 KB
testcase_33 AC 6 ms
5,488 KB
testcase_34 AC 21 ms
5,384 KB
testcase_35 AC 4 ms
13,828 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
5,504 KB
testcase_38 AC 2 ms
5,552 KB
testcase_39 AC 2 ms
5,496 KB
testcase_40 AC 2 ms
5,388 KB
testcase_41 AC 2 ms
5,668 KB
testcase_42 AC 3 ms
5,632 KB
testcase_43 AC 4 ms
5,632 KB
testcase_44 WA -
testcase_45 AC 5 ms
8,008 KB
testcase_46 AC 5 ms
5,620 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<int> st, buf;
int pre[3000000];
int idx[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);
            pre[n+m] = n;
            idx[n+m] = i;
            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];
                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();
                }
            }
            for(int j = 0; j < N; j++){
                if(used_idx.count(j) == 0) cout << 'x';
                else cout << 'o';
            }
            cout << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}
0