結果

問題 No.10 +か×か
ユーザー 沙耶花沙耶花
提出日時 2021-10-20 21:06:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 344 ms / 5,000 ms
コード長 854 bytes
コンパイル時間 4,326 ms
コンパイル使用メモリ 261,596 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-21 06:35:06
合計ジャッジ時間 5,983 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

bool check(int s,vector<int> a,int goal){
	vector<bool> dp(goal+1,false);
	dp[s] = true;
	rep(i,a.size()){
		vector<bool> ndp(goal+1,false);
		rep(j,goal+1){
			if(dp[j]){
				if(j+a[i]<=goal)ndp[j+a[i]] = true;
				if(j*a[i]<=goal)ndp[j*a[i]] = true;
			}
		}
		swap(dp,ndp);
	}
	return dp.back();
	
}

int main(){
	
	int N,T;
	cin>>N>>T;
	
	vector<int> A(N);
	rep(i,N)cin>>A[i];
	
	int cur = A[0];
	A.erase(A.begin());
	string ans = "";
	for(int i=1;i<N;i++){
		int t = A[0];
		A.erase(A.begin());
		if(check(cur + t,A,T)){
			ans += '+';
			cur += t;
		}
		else{
			ans += '*';
			cur *= t;
		}
	}
	
	cout<<ans<<endl;
		
	
	
	return 0;
}
0