結果

問題 No.10 +か×か
ユーザー furafura
提出日時 2020-01-02 17:57:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 651 bytes
コンパイル時間 1,602 ms
コンパイル使用メモリ 169,476 KB
実行使用メモリ 8,476 KB
最終ジャッジ日時 2024-05-02 06:40:21
合計ジャッジ時間 1,964 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,948 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
6,940 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 8 ms
7,256 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n,total; scanf("%d%d",&n,&total);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	static char dp[50][100001];
	rep(i,n) rep(x,total+1) dp[i][x]='x';
	dp[0][a[0]]='o';
	rep(i,n-1){
		rep(x,total+1) if(dp[i][x]!='x') if(x*a[i+1]<=total) dp[i+1][x*a[i+1]]='*';
		rep(x,total+1) if(dp[i][x]!='x') if(x+a[i+1]<=total) dp[i+1][x+a[i+1]]='+';
	}

	string ans;
	int res=total;
	for(int i=n-1;i>0;i--){
		char c=dp[i][res];
		ans+=c;
		if(c=='+') res-=a[i];
		else       res/=a[i];
	}
	reverse(ans.begin(),ans.end());
	puts(ans.c_str());

	return 0;
}
0