結果
問題 | No.10 +か×か |
ユーザー |
![]() |
提出日時 | 2016-04-23 21:44:45 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 793 ms / 5,000 ms |
コード長 | 1,730 bytes |
コンパイル時間 | 546 ms |
コンパイル使用メモリ | 65,980 KB |
実行使用メモリ | 334,336 KB |
最終ジャッジ日時 | 2024-12-14 15:35:36 |
合計ジャッジ時間 | 3,896 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
ソースコード
//#include <algorithm> //#include <cmath> //#include <cstring> #include <iostream> #include <map> #include <numeric> //#include <queue> //#include <set> //#include <sstream> //#include <stack> #include <string> #include <vector> #include <iterator> //#define pb push_back //#define puts(x) cout << #x << " : " << x << endl; //#pragma GCC diagnostic ignored "-Wconversion" //#define REP(i,n) for (int i=0;i<(n);i++) //#define REPE(i,n) for (int i=0;i<=(n);i++) //#define init(a,b) memset((a), (b), (sizeof(a))); //#define PI 3.14159265 //#define EPS (1e-10) //#define EQ(a,b) (abs((a)-(b)) < EPS) using namespace std; //typedef long long ll; //#define int long long typedef pair<int, int> P; string dp[55][100005]; int a[55]; signed main() { int n; int total; cin>>n>>total; for(int i=0;i<n;i++)cin>>a[i]; for(int i=0;i<n;i++){ fill(dp[i], dp[i] + 100005, ""); } dp[0][0]="0"; for(int i=0;i<n;i++){ for(int j=0;j<=100000;j++){ if(!dp[i][j].empty()){ int plus = j + a[i]; int mul = j * a[i]; string s1 = dp[i][j] + "0"; string s2 = dp[i][j] + "1"; if(plus <= total){ if(dp[i+1][plus].empty() || dp[i + 1][plus] > s1){ dp[i+1][plus] = s1; } } if(mul <= total){ if (dp[i+1][mul].empty() || dp[i+1][mul] > s2){ dp[i+1][mul] = s2; } } } } } for(int i=2;i<dp[n][total].size();i++){ if(dp[n][total][i]=='0')cout<<'+'; else cout<<'*'; } cout<<endl; return 0; }