結果

問題 No.10 +か×か
ユーザー 沙耶花沙耶花
提出日時 2021-10-20 21:06:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 409 ms / 5,000 ms
コード長 854 bytes
コンパイル時間 4,740 ms
コンパイル使用メモリ 263,724 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-08 12:05:17
合計ジャッジ時間 6,535 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 409 ms
5,376 KB
testcase_04 AC 170 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 403 ms
5,376 KB
testcase_07 AC 197 ms
5,376 KB
testcase_08 AC 28 ms
5,376 KB
testcase_09 AC 38 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,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