結果

問題 No.332 数列をプレゼントに
ユーザー piyoko_212piyoko_212
提出日時 2015-12-25 00:18:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,275 ms / 2,000 ms
コード長 1,094 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 44,696 KB
実行使用メモリ 103,296 KB
最終ジャッジ日時 2023-08-25 21:10:26
合計ジャッジ時間 8,446 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
9,028 KB
testcase_01 AC 7 ms
6,992 KB
testcase_02 AC 4 ms
4,940 KB
testcase_03 AC 4 ms
4,884 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 74 ms
54,144 KB
testcase_06 AC 90 ms
66,436 KB
testcase_07 AC 121 ms
88,944 KB
testcase_08 AC 91 ms
68,480 KB
testcase_09 AC 12 ms
11,104 KB
testcase_10 AC 19 ms
13,180 KB
testcase_11 AC 69 ms
52,080 KB
testcase_12 AC 125 ms
93,060 KB
testcase_13 AC 97 ms
72,520 KB
testcase_14 AC 50 ms
37,772 KB
testcase_15 AC 119 ms
86,896 KB
testcase_16 AC 103 ms
76,612 KB
testcase_17 AC 117 ms
88,964 KB
testcase_18 AC 97 ms
68,364 KB
testcase_19 AC 99 ms
74,628 KB
testcase_20 AC 119 ms
86,792 KB
testcase_21 AC 126 ms
92,944 KB
testcase_22 AC 114 ms
84,864 KB
testcase_23 AC 121 ms
90,984 KB
testcase_24 AC 119 ms
90,976 KB
testcase_25 AC 124 ms
90,892 KB
testcase_26 AC 124 ms
90,912 KB
testcase_27 AC 123 ms
90,896 KB
testcase_28 AC 124 ms
90,892 KB
testcase_29 AC 121 ms
90,968 KB
testcase_30 AC 120 ms
91,008 KB
testcase_31 AC 122 ms
90,940 KB
testcase_32 AC 123 ms
90,952 KB
testcase_33 AC 122 ms
86,900 KB
testcase_34 AC 130 ms
84,752 KB
testcase_35 AC 177 ms
84,884 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 123 ms
92,988 KB
testcase_38 AC 126 ms
93,052 KB
testcase_39 AC 127 ms
92,988 KB
testcase_40 AC 143 ms
103,256 KB
testcase_41 AC 142 ms
103,188 KB
testcase_42 AC 141 ms
103,164 KB
testcase_43 AC 142 ms
103,296 KB
testcase_44 AC 142 ms
103,184 KB
testcase_45 AC 1,275 ms
80,760 KB
testcase_46 AC 61 ms
47,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<algorithm>
using namespace std;
char dp[110][1010000];
int c[110];
pair<int,int> p[110];
char str[110];
int main(){
	int a;
	long long b;scanf("%d%lld",&a,&b);
	for(int i=0;i<a;i++)scanf("%d",c+i);
	for(int i=0;i<a;i++)p[i]=make_pair(c[i],i);
	std::sort(p,p+a);
	int at=0;
	while(at<a&&p[at].first<=10000){
		at++;
	}
	for(int i=0;i<=at;i++)for(int j=0;j<1010000;j++)dp[i][j]=-1;
	dp[0][0]=0;
	for(int i=0;i<at;i++){
		for(int j=0;j<1010000;j++){
			if(dp[i][j]==-1)continue;
			dp[i+1][j]=1;
			dp[i+1][j+p[i].first]=2;
		}
	}
	int n=a-at;
	for(int i=0;i<(1<<n);i++){
		long long tmp=0;
		for(int j=0;j<n;j++){
			if(i&(1<<j))tmp+=p[at+j].first;
		}
		//printf("%d\n",i);fflush(stdout);
		if(tmp<=b&&b-tmp<1010000&&dp[at][b-tmp]!=-1){
			for(int j=0;j<n;j++){
				if(i&(1<<j))str[p[at+j].second]='o';
				else str[p[at+j].second]='x';
			}
			int y=b-tmp;
			for(int j=at;j>0;j--){
				if(dp[j][y]==1){
					str[p[j-1].second]='x';
				}else{
					str[p[j-1].second]='o';
					y-=p[j-1].first;
				}
			}
			printf("%s\n",str);
			return 0;
		}
	}
	printf("No\n");
}
0