結果

問題 No.10 +か×か
ユーザー troro_kelptroro_kelp
提出日時 2018-12-30 23:30:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 1,039 bytes
コンパイル時間 791 ms
コンパイル使用メモリ 93,144 KB
実行使用メモリ 12,628 KB
最終ジャッジ日時 2023-08-21 06:25:07
合計ジャッジ時間 1,603 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
int N, Total;
int A[51];
int dp[51][100100];
string S;
// bool operator<(const pair<int, int> &a, const pair<int, int> &b)
// {
//     if (a.first == b.first)
//         return a.second < b.second;
//     return a.first < b.first;
// };

void dfs(int cur, int v)
{
    if (v > Total)
        return;
    if (cur == N)
    {
        if (v == Total)
        {
            cout << S << endl;
            exit(0);
        }
        return;
    }
    if (dp[cur][v])
        return;
    dp[cur][v] = 1;

    S += "+";
    dfs(cur + 1, v + A[cur]);
    S.pop_back();
    S += "*";
    dfs(cur + 1, v * A[cur]);
    S.pop_back();
}
int main(void)
{

    cin >> N >> Total;
    for (int i = 0; i < N; ++i)
        cin >> A[i];

    dfs(1, A[0]);
    return 0;
}
0