結果

問題 No.332 数列をプレゼントに
ユーザー chocoruskchocorusk
提出日時 2019-01-22 13:13:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 1,716 bytes
コンパイル時間 2,036 ms
コンパイル使用メモリ 98,308 KB
実行使用メモリ 99,708 KB
最終ジャッジ日時 2023-10-13 17:39:17
合計ジャッジ時間 5,099 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,648 KB
testcase_01 AC 1 ms
5,540 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 1 ms
5,464 KB
testcase_04 AC 1 ms
4,356 KB
testcase_05 AC 15 ms
52,984 KB
testcase_06 AC 16 ms
65,048 KB
testcase_07 AC 20 ms
85,748 KB
testcase_08 AC 15 ms
64,984 KB
testcase_09 AC 3 ms
7,796 KB
testcase_10 AC 4 ms
11,564 KB
testcase_11 AC 12 ms
50,644 KB
testcase_12 AC 20 ms
89,600 KB
testcase_13 AC 16 ms
69,112 KB
testcase_14 AC 9 ms
36,304 KB
testcase_15 AC 19 ms
85,504 KB
testcase_16 AC 15 ms
75,092 KB
testcase_17 AC 18 ms
87,372 KB
testcase_18 AC 14 ms
64,852 KB
testcase_19 AC 15 ms
73,044 KB
testcase_20 AC 21 ms
83,456 KB
testcase_21 AC 20 ms
91,656 KB
testcase_22 AC 19 ms
81,536 KB
testcase_23 AC 20 ms
87,552 KB
testcase_24 AC 20 ms
87,620 KB
testcase_25 AC 20 ms
87,612 KB
testcase_26 AC 19 ms
87,492 KB
testcase_27 AC 20 ms
89,540 KB
testcase_28 AC 20 ms
87,780 KB
testcase_29 AC 20 ms
87,532 KB
testcase_30 AC 20 ms
87,496 KB
testcase_31 AC 20 ms
87,488 KB
testcase_32 AC 20 ms
89,496 KB
testcase_33 AC 18 ms
85,332 KB
testcase_34 AC 19 ms
83,292 KB
testcase_35 AC 23 ms
81,380 KB
testcase_36 AC 2 ms
4,352 KB
testcase_37 AC 20 ms
91,444 KB
testcase_38 AC 19 ms
91,452 KB
testcase_39 AC 19 ms
91,432 KB
testcase_40 AC 21 ms
99,688 KB
testcase_41 AC 21 ms
99,644 KB
testcase_42 AC 21 ms
99,636 KB
testcase_43 AC 21 ms
99,708 KB
testcase_44 AC 20 ms
99,660 KB
testcase_45 AC 121 ms
77,152 KB
testcase_46 AC 10 ms
46,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, int> P;
int n; ll x;
vector<ll> s1;
ll a[101];
vector<int> ind1, ind2;
ll sum1;
ll s2;
ll ans1, ans2;
bool used2[25];
bool used[25];
void dfs(int i){
	if(ans1 || ans2) return;
	if(i==ind2.size()){
		if(x-s2<0 || x-s2>sum1) return;
		int j=lower_bound(s1.begin(), s1.end(), x-s2)-s1.begin();
		if(s1[j]==x-s2){
			ans1=s1[j], ans2=s2;
			for(int j=0; j<ind2.size(); j++) used2[j]=used[j];
		}
      return;
	}
	dfs(i+1);
	used[i]=1;
	s2+=a[ind2[i]];
	dfs(i+1);
	used[i]=0;
	s2-=a[ind2[i]];
}
int main()
{
	cin>>n>>x;
	for(int i=0; i<n; i++){
		cin>>a[i];
		if(a[i]<=10000) ind1.push_back(i), sum1+=a[i];
		else ind2.push_back(i);
	}
	bool dp[101][1000001];
	fill(dp[0], dp[0]+sum1+1, 0);
	dp[0][0]=1;
	for(int i=1; i<=ind1.size(); i++){
		int i1=ind1[i-1];
		for(int j=0; j<=sum1; j++) dp[i][j]=dp[i-1][j];
		for(int j=a[i1]; j<=sum1; j++) dp[i][j]|=dp[i-1][j-a[i1]];
	}
	for(int i=0; i<=sum1; i++) if(dp[ind1.size()][i]) s1.push_back(i);
	dfs(0);
	if(ans1==0 && ans2==0){
		cout<<"No"<<endl;
		return 0;
	}
	char ans[101];
	int i1=ind1.size();
	while(i1){
		if(dp[i1-1][ans1]){
			ans[ind1[i1-1]]='x';
		}else{
			ans1-=a[ind1[i1-1]];
			ans[ind1[i1-1]]='o';
		}
		i1--;
	}
	for(int i=0; i<ind2.size(); i++){
		if(used2[i]) ans[ind2[i]]='o';
		else ans[ind2[i]]='x';
	}
	for(int i=0; i<n; i++) cout<<ans[i];
	cout<<endl;
	return 0;
}
0