結果

問題 No.10 +か×か
ユーザー codershifthcodershifth
提出日時 2016-08-30 01:38:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 73 ms / 5,000 ms
コード長 1,468 bytes
コンパイル時間 1,486 ms
コンパイル使用メモリ 153,764 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-21 06:20:47
合計ジャッジ時間 2,195 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 43 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 73 ms
4,380 KB
testcase_07 AC 38 ms
4,380 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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