結果

問題 No.332 数列をプレゼントに
ユーザー 🐬hec🐬hec
提出日時 2015-12-25 02:24:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 255 ms / 2,000 ms
コード長 1,086 bytes
コンパイル時間 1,423 ms
コンパイル使用メモリ 160,696 KB
実行使用メモリ 4,436 KB
最終ジャッジ日時 2023-08-25 21:15:03
合計ジャッジ時間 8,816 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 242 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 230 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 11 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 5 ms
4,436 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 104 ms
4,380 KB
testcase_24 AC 244 ms
4,380 KB
testcase_25 AC 233 ms
4,380 KB
testcase_26 AC 157 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 235 ms
4,376 KB
testcase_29 AC 235 ms
4,384 KB
testcase_30 AC 52 ms
4,380 KB
testcase_31 AC 234 ms
4,380 KB
testcase_32 AC 233 ms
4,380 KB
testcase_33 AC 237 ms
4,380 KB
testcase_34 AC 242 ms
4,380 KB
testcase_35 AC 241 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 244 ms
4,384 KB
testcase_38 AC 246 ms
4,380 KB
testcase_39 AC 243 ms
4,384 KB
testcase_40 AC 245 ms
4,380 KB
testcase_41 AC 234 ms
4,376 KB
testcase_42 AC 234 ms
4,376 KB
testcase_43 AC 255 ms
4,376 KB
testcase_44 AC 16 ms
4,376 KB
testcase_45 AC 249 ms
4,380 KB
testcase_46 AC 250 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long ;
using pii=pair<int,int>;

int n;
ll x;
pii a[110];
map<ll,ll> dp[110];

void output(string arg){
	string ans=arg;
	rep(i,n) ans[a[i].second]=arg[i];
	cout << ans << endl;
	return ;
}

int main(void){
	cin >> n >> x;
	const int m=min(n,20);
	const int offset=n-m;
	
	rep(i,n) cin >> a[i].first,a[i].second=i;
	sort(a,a+n);

	dp[0][0]=-1LL;
	rep(i,offset){
		for(auto &it:dp[i]){
			ll cur=it.first;
			dp[i+1][cur]=cur;
			dp[i+1][cur+a[i].first]=cur;
		}		
	}

	rep(mask,1<<m){
		ll cur=0LL;
		string ans="";
		rep(i,m){
			if(mask&(1<<i)){
				cur+=a[i+offset].first;
				ans+="o";
			}else{
				ans+="x";
			}
		}

		if(x<cur) continue;
		cur=x-cur;

		if(dp[offset].find(cur)!=dp[offset].end()){
			reverse(ans.begin(),ans.end());	
			for(int i=offset;i>0;--i){
				if(cur!=dp[i][cur]){
					ans+="o";
				}else{
					ans+="x";
				}
				cur=dp[i][cur];
			}
			assert(cur==0LL);
			reverse(ans.begin(),ans.end());
			output(ans);
			return 0;
		}
	}
	puts("No");
	return 0;
}

0