結果

問題 No.10 +か×か
ユーザー simezi_tansimezi_tan
提出日時 2015-07-21 17:54:45
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 982 bytes
コンパイル時間 1,349 ms
コンパイル使用メモリ 146,456 KB
実行使用メモリ 21,244 KB
最終ジャッジ日時 2023-09-22 20:56:48
合計ジャッジ時間 2,279 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const int MX = 110000;
int n, total, a[50], dp[51][MX];
	
int main(){
	cin >> n >> total;
	rep(i, n) cin >> a[i];
	
	dp[0][a[0]] = -1;
	for(int i = 1; i < n; i++) rep(j, MX) if(dp[i - 1][j]){
		
		if(j + a[i] < MX) dp[i][j + a[i]] = max(dp[i][j + a[i]], 2);
		if(j * a[i] < MX) dp[i][j * a[i]] = max(dp[i][j * a[i]], 1);
	}
	string ans;
	for(int i = n - 1; i > 0; i--){
		ans += dp[i][total] == 2 ? "+" : "*";
		total = dp[i][total] == 2 ? total - a[i] : total / a[i];
	}
	dbg(total);
	reverse(all(ans));
	cout << ans << endl;
	
	return 0;
}
0