結果

問題 No.10 +か×か
コンテスト
ユーザー codershifth
提出日時 2016-08-30 01:38:44
言語 C++11(廃止可能性あり)
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 61 ms / 5,000 ms
コード長 1,468 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,401 ms
コンパイル使用メモリ 167,216 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-12-06 14:35:16
合計ジャッジ時間 2,248 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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>> vis(N+1, vector<bool>(Total+1, false));
            string ans;
            function<bool(int,int,string)> dfs = [&](int s, int k, string str)
            {
                if ( s > Total )
                    return false;
                if (k == N-1)
                {
                    if ( s == Total )
                    {
                        ans = str;
                        return true;
                    }
                    return false;
                }
                if ( vis[k][s] )
                    return false;
                vis[k][s] = true;
                if ( dfs(s+A[k+1], k+1, str+'+') )
                    return true;
                if ( dfs(s*A[k+1], k+1, str+'*') )
                    return true;
                return false;
            };
            dfs(A[0], 0, "");
            cout<<ans<<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
0