結果
問題 | No.10 +か×か |
ユーザー |
![]() |
提出日時 | 2016-08-30 01:04:37 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,832 bytes |
コンパイル時間 | 2,286 ms |
コンパイル使用メモリ | 175,800 KB |
実行使用メモリ | 814,048 KB |
最終ジャッジ日時 | 2024-11-14 06:53:56 |
合計ジャッジ時間 | 15,318 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 9 TLE * 2 MLE * 1 |
ソースコード
#include <bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; #define FOR(i,a,b) for(int (i)=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define RANGE(vec) (vec).begin(),(vec).end() using namespace std; class Yuki0010 { public: void solve(void) { int N,Total; cin>>N>>Total; vector<int> A(N); REP(i,N) cin>>A[i]; vector<vector<bool>> dp(N+1, vector<bool>(Total+1, false)); dp[0][A[0]] = true; REP(i,N-1) { REP(s,Total+1) { if ( !dp[i][s] ) continue; int a = A[i+1]; if ( s+a <= Total ) dp[i+1][s+a] = true; if ( s*a <= Total ) dp[i+1][s*a] = true; } } vector<string> ans; function<void(int,int,string)> collect = [&](int s, int k, string str) { if ( k < 0 ) return; if (k == 0 && dp[k][s] ) { reverse(RANGE(str)); ans.push_back(str); return; } if ( !dp[k][s] ) return; if ( s >= A[k] ) collect(s-A[k], k-1, str+'+'); if ( s % A[k] == 0 ) collect(s/A[k], k-1, str+'*'); }; collect(Total, N-1, ""); sort(RANGE(ans)); reverse(RANGE(ans)); cout<<ans[0]<<endl; } }; #if 1 int main(int argc, char *argv[]) { ios::sync_with_stdio(false); auto obj = new Yuki0010(); obj->solve(); delete obj; return 0; } #endif