結果

問題 No.332 数列をプレゼントに
ユーザー rng_58rng_58
提出日時 2015-12-25 01:11:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 1,528 bytes
コンパイル時間 903 ms
コンパイル使用メモリ 93,392 KB
実行使用メモリ 85,472 KB
最終ジャッジ日時 2023-08-25 21:11:58
合計ジャッジ時間 5,846 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,512 KB
testcase_01 AC 3 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 3 ms
4,640 KB
testcase_05 AC 42 ms
46,280 KB
testcase_06 AC 53 ms
58,568 KB
testcase_07 AC 74 ms
81,092 KB
testcase_08 AC 55 ms
60,624 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 14 ms
11,540 KB
testcase_11 AC 41 ms
44,220 KB
testcase_12 AC 74 ms
83,100 KB
testcase_13 AC 56 ms
62,724 KB
testcase_14 AC 29 ms
29,900 KB
testcase_15 AC 62 ms
69,076 KB
testcase_16 AC 65 ms
72,968 KB
testcase_17 AC 74 ms
83,428 KB
testcase_18 AC 66 ms
72,980 KB
testcase_19 AC 66 ms
75,004 KB
testcase_20 AC 61 ms
68,808 KB
testcase_21 AC 67 ms
74,912 KB
testcase_22 AC 59 ms
66,712 KB
testcase_23 AC 74 ms
85,144 KB
testcase_24 AC 73 ms
85,152 KB
testcase_25 AC 74 ms
85,192 KB
testcase_26 AC 75 ms
85,228 KB
testcase_27 AC 75 ms
85,192 KB
testcase_28 AC 75 ms
85,144 KB
testcase_29 AC 75 ms
85,252 KB
testcase_30 AC 75 ms
85,324 KB
testcase_31 AC 74 ms
85,252 KB
testcase_32 AC 74 ms
85,404 KB
testcase_33 AC 74 ms
85,204 KB
testcase_34 AC 77 ms
85,472 KB
testcase_35 AC 76 ms
85,192 KB
testcase_36 AC 2 ms
4,420 KB
testcase_37 AC 74 ms
85,464 KB
testcase_38 AC 73 ms
85,196 KB
testcase_39 AC 74 ms
85,456 KB
testcase_40 AC 77 ms
85,188 KB
testcase_41 AC 74 ms
85,336 KB
testcase_42 AC 76 ms
85,308 KB
testcase_43 AC 75 ms
85,188 KB
testcase_44 AC 76 ms
85,184 KB
testcase_45 AC 76 ms
85,176 KB
testcase_46 AC 29 ms
32,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

typedef long long ll;

int N,K;
int a[110];
vector <pair <int, int> > v; // a[i], id
bitset <8000010> dp[90];

bool found = false;
bool ans[110];
bool ans2[110];

void check(ll X){
	int i;
	
	if(X < 0 || X >= 8000010 || found) return;
	
	if(!dp[N-K][X]) return;
	
	found = true;
	for(i=N-K-1;i>=0;i--){
		int id = v[i].second;
		if(a[id] <= X && dp[i][X-a[id]]){
			ans[id] = true;
			X -= a[id];
		} else {
			ans[id] = false;
		}
	}
	
	REP(i,N) ans2[i] = ans[i];
}

void dfs(int pos, ll X){
	if(pos == N-K){
		check(X);
		return;
	}
	
	int id = v[pos-1].second;
	ans[id] = false;
	dfs(pos-1, X);
	ans[id] = true;
	dfs(pos-1, X-a[id]);
}

int main(void){
	int i;
	
	ll X;
	cin >> N >> X;
	REP(i,N) cin >> a[i];
	
	REP(i,N) v.push_back(make_pair(a[i], i));
	sort(v.begin(),v.end());
	
	K = min(N, 20);
	dp[0].reset();
	dp[0][0] = true;
	REP(i,N-K) dp[i+1] = ((dp[i] << a[v[i].second]) | dp[i]);
	dfs(N, X);
	
	if(!found){
		cout << "No" << endl;
	} else {
		string s;
		REP(i,N) s += (ans2[i] ? 'o' : 'x');
		cout << s << endl;
	}
	
	return 0;
}
0