結果

問題 No.10 +か×か
コンテスト
ユーザー stqn
提出日時 2014-11-25 20:38:34
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 808 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,114 ms
コンパイル使用メモリ 176,436 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2026-06-06 10:40:33
合計ジャッジ時間 9,690 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 TLE * 1 -- * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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