結果

問題 No.10 +か×か
ユーザー stqnstqn
提出日時 2014-11-25 20:38:34
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 808 bytes
コンパイル時間 1,190 ms
コンパイル使用メモリ 144,796 KB
実行使用メモリ 8,768 KB
最終ジャッジ日時 2023-08-31 01:12:41
合計ジャッジ時間 8,196 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define long int64_t
#define ulong uint64_t

const int N = 50;
int n, total, a[N];

void input()
{
    cin >> n >> total;
    rep(i, n) cin >> a[i];
}

bool dfs(int i, int cur)
{
    if (i == n) return cur == total;
    return dfs(i + 1, cur + a[i]) or dfs(i + 1, cur * a[i]);
}

void solve()
{
    string ans;
    int cur = a[0];
    repi(i, 1, n) {
        if (dfs(i + 1, cur + a[i])) {
            ans.push_back('+'), cur += a[i];
        } else {
            ans.push_back('*'), cur *= a[i];
        }
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    input();
    solve();
}
0