結果

問題 No.332 数列をプレゼントに
ユーザー rng_58rng_58
提出日時 2015-12-25 01:08:53
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,529 bytes
コンパイル時間 1,371 ms
コンパイル使用メモリ 93,532 KB
実行使用メモリ 16,704 KB
最終ジャッジ日時 2023-10-19 03:18:51
合計ジャッジ時間 5,113 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,308 KB
testcase_01 AC 2 ms
5,964 KB
testcase_02 AC 2 ms
5,960 KB
testcase_03 AC 2 ms
5,964 KB
testcase_04 AC 2 ms
5,964 KB
testcase_05 AC 260 ms
10,628 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

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 <800010> dp[90];

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

void check(ll X){
	int i;
	
	if(X < 0 || X >= 8000010 || found) return;
	
	dp[0].reset();
	dp[0][0] = true;
	REP(i,N-K) dp[i+1] = ((dp[i] << a[v[i].second]) | dp[i]);
	
	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);
	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