結果

問題 No.332 数列をプレゼントに
ユーザー mamekinmamekin
提出日時 2017-09-23 16:45:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,076 bytes
コンパイル時間 1,096 ms
コンパイル使用メモリ 110,984 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-08 23:23:27
合計ジャッジ時間 8,180 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 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 2 ms
4,384 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 RE -
testcase_08 AC 1 ms
4,380 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 RE -
testcase_18 AC 4 ms
4,380 KB
testcase_19 RE -
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 RE -
testcase_24 AC 2 ms
4,380 KB
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 1 ms
4,380 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

bool solve(const vector<int>& a, int x, vector<bool>& ans)
{
    int n = a.size();
    vector<int> dp(x+1, -1);
    dp[0] = 0;
    for(int i=0; i<n; ++i){
        for(int j=x; j>=a[i]; --j){
            if(dp[j] == -1 && dp[j-a[i]] != -1)
                dp[j] = i;
        }
    }
    if(dp[x] == -1)
        return false;

    ans.assign(n, false);
    int i = x;
    while(i != 0){
        ans[dp[i]] = true;
        i -= a[dp[i]];
    }
    return true;
}

int main()
{
    int n;
    long long x;
    cin >> n >> x;

    vector<int> a, b;
    vector<int> aIndex, bIndex;
    for(int i=0; i<n; ++i){
        int c;
        cin >> c;
        if(c < 20000){
            a.push_back(c);
            aIndex.push_back(i);
        }
        else{
            b.push_back(c);
            bIndex.push_back(i);
        }
    }
    
    int aSum = accumulate(a.begin(), a.end(), 0);
    int m = b.size();
    for(int i=0; i<(1<<m); ++i){
        bitset<32> bs(i);
        long long y = x;
        for(int j=0; j<m; ++j){
            if(bs[j])
                y -= b[j];
        }

        if(y <= aSum){
            vector<bool> used;
            if(solve(a, (int)y, used)){
                string ans(n, 'x');
                for(int j=0; j<m; ++j){
                    if(bs[j])
                        ans[bIndex[j]] = 'o';
                }
                for(unsigned j=0; j<used.size(); ++j){
                    if(used[j])
                        ans[aIndex[j]] = 'o';
                }
                cout << ans << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}
0