結果
問題 | No.10 +か×か |
ユーザー |
![]() |
提出日時 | 2021-10-20 21:06:54 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 337 ms / 5,000 ms |
コード長 | 854 bytes |
コンパイル時間 | 4,783 ms |
コンパイル使用メモリ | 251,884 KB |
最終ジャッジ日時 | 2025-01-25 02:04:47 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
ソースコード
#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; }