結果
| 問題 | 
                            No.10 +か×か
                             | 
                    
| コンテスト | |
| ユーザー | 
                             codershifth
                         | 
                    
| 提出日時 | 2016-08-30 01:20:19 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 2,018 bytes | 
| コンパイル時間 | 1,910 ms | 
| コンパイル使用メモリ | 181,784 KB | 
| 実行使用メモリ | 814,720 KB | 
| 最終ジャッジ日時 | 2024-11-14 06:55:25 | 
| 合計ジャッジ時間 | 23,662 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 8 TLE * 4 | 
ソースコード
#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;
            set<string> vis;
            function<void(int,int,string)> collect = [&](int s, int k, string str)
            {
                if ( vis.count(str) )
                    return;
                vis.insert(str);
                if ( s > Total )
                    return;
                if ( k > N-1 )
                    return;
                if ( !dp[k][s] )
                    return;
                if ( k == N-1 )
                {
                    if ( s == Total )
                    {
                        ans.push_back(str);
                        return;
                    }
                    return;
                }
                collect(s+A[k+1], k+1, str+'+');
                collect(s*A[k+1], k+1, str+'*');
            };
            collect(A[0], 0, "");
            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
            
            
            
        
            
codershifth