結果

問題 No.10 +か×か
ユーザー chocoruskchocorusk
提出日時 2019-01-24 19:14:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 887 bytes
コンパイル時間 654 ms
コンパイル使用メモリ 93,644 KB
実行使用メモリ 8,456 KB
最終ジャッジ日時 2023-08-21 06:25:21
合計ジャッジ時間 1,394 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,340 KB
testcase_01 AC 3 ms
8,260 KB
testcase_02 AC 3 ms
8,240 KB
testcase_03 AC 9 ms
8,236 KB
testcase_04 AC 7 ms
8,300 KB
testcase_05 AC 4 ms
8,456 KB
testcase_06 AC 10 ms
8,232 KB
testcase_07 AC 8 ms
8,348 KB
testcase_08 AC 5 ms
8,304 KB
testcase_09 AC 6 ms
8,264 KB
testcase_10 AC 4 ms
8,456 KB
testcase_11 AC 4 ms
8,388 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<int, int> P;

int main()
{
	int n, tot; cin>>n>>tot;
	bool dp[51][100001]={};
	int a[51];
	for(int i=0; i<n; i++) cin>>a[i];
	dp[n-1][tot]=1;
	for(int i=n-1; i>=1; i--){
		for(int k=1; k<=tot; k++){
			if(!dp[i][k]) continue;
			if(k-a[i]>=1){
				dp[i-1][k-a[i]]=1;
			}
			if(k%a[i]==0){
				dp[i-1][k/a[i]]=1;
			}
		}
	}
	string ans;
	int s=a[0];
	for(int i=1; i<n; i++){
		if(s+a[i]<=tot && dp[i][s+a[i]]){
			ans+='+';
			s+=a[i];
		}else{
			ans+='*';
			s*=a[i];
		}
	}
	cout<<ans<<endl;
	return 0;
}
0