結果

問題 No.332 数列をプレゼントに
ユーザー climpetclimpet
提出日時 2015-12-25 00:35:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 1,167 bytes
コンパイル時間 598 ms
コンパイル使用メモリ 70,244 KB
実行使用メモリ 128,936 KB
最終ジャッジ日時 2023-08-25 21:10:55
合計ジャッジ時間 6,822 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
11,656 KB
testcase_01 AC 7 ms
10,404 KB
testcase_02 AC 5 ms
7,940 KB
testcase_03 AC 5 ms
7,940 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 70 ms
75,076 KB
testcase_06 AC 82 ms
88,532 KB
testcase_07 AC 110 ms
116,620 KB
testcase_08 AC 84 ms
92,012 KB
testcase_09 AC 11 ms
15,316 KB
testcase_10 AC 21 ms
25,192 KB
testcase_11 AC 66 ms
70,248 KB
testcase_12 AC 112 ms
118,984 KB
testcase_13 AC 87 ms
93,472 KB
testcase_14 AC 50 ms
55,484 KB
testcase_15 AC 101 ms
109,172 KB
testcase_16 AC 89 ms
95,652 KB
testcase_17 AC 105 ms
111,612 KB
testcase_18 AC 105 ms
112,748 KB
testcase_19 AC 87 ms
93,396 KB
testcase_20 AC 101 ms
107,988 KB
testcase_21 AC 109 ms
116,600 KB
testcase_22 AC 98 ms
104,356 KB
testcase_23 AC 108 ms
116,932 KB
testcase_24 AC 109 ms
116,688 KB
testcase_25 AC 109 ms
116,684 KB
testcase_26 AC 108 ms
116,668 KB
testcase_27 AC 108 ms
116,672 KB
testcase_28 AC 107 ms
116,596 KB
testcase_29 AC 107 ms
116,940 KB
testcase_30 AC 107 ms
116,756 KB
testcase_31 AC 108 ms
116,696 KB
testcase_32 AC 107 ms
116,620 KB
testcase_33 AC 102 ms
109,304 KB
testcase_34 AC 102 ms
106,784 KB
testcase_35 AC 120 ms
128,800 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 108 ms
116,508 KB
testcase_38 AC 108 ms
116,668 KB
testcase_39 AC 108 ms
116,600 KB
testcase_40 AC 120 ms
128,796 KB
testcase_41 AC 120 ms
128,936 KB
testcase_42 AC 120 ms
128,672 KB
testcase_43 AC 120 ms
128,688 KB
testcase_44 AC 119 ms
128,676 KB
testcase_45 AC 119 ms
127,764 KB
testcase_46 AC 55 ms
59,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <utility>
using namespace std;

const int lim = 100006;
const int sz = lim * 100 + 6;

typedef long long LL;
typedef bitset<sz> bsz;
typedef pair<int,int> pii;
typedef pair<LL,int> pli;

int n;
vector<pii> big, small;
vector<bsz> dp;

void dfs(int k, int S, LL rest){
	if(rest < 0){ return; }
	if(k == (int)big.size()){
		if(rest >= sz || !dp.back()[rest]){ return; }
		string ans(n, 'x');
		for(int i = big.size(); i--; )
		if(S >> i & 1){
			ans[big[i].second] = 'o';
		}
		for(int p = small.size() - 1; p >= 0; --p){
			if(!dp[p][rest]){
				ans[small[p].second] = 'o';
				rest -= small[p].first;
			}
		}
		cout << ans << '\n';
		exit(0);
	}
	else{
		dfs(k + 1, S, rest);
		dfs(k + 1, S | 1 << k, rest - big[k].first);
	}
}

int main(){
	LL x;
	
	cin >> n >> x;
	for(int i = 0; i < n; ++i){
		int a;
		cin >> a;
		(a < lim ? small : big).emplace_back(a, i);
	}
	
	dp.resize(small.size() + 1);
	dp[0].set(0);
	for(size_t i = 0; i < small.size(); ++i){
		dp[i + 1] = dp[i] | dp[i] << small[i].first;
	}
	
	dfs(0, 0, x);
	
	cout << "No\n";
}
0