結果

問題 No.10 +か×か
コンテスト
ユーザー nukacha
提出日時 2017-05-03 06:10:13
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 730 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 409 ms
コンパイル使用メモリ 78,964 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2026-04-04 10:29:08
合計ジャッジ時間 6,971 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 WA * 1 TLE * 1 -- * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <string>

int n;
int t;
std::vector<int> a(50, -1);
std::string s;

bool solve(int r, int i) {
    if (r > t) {
        return false;
    }
    if (i == n) {
        if (r == t) {
            return true;
        } else {
            return false;
        }
    }

    if (solve(r + a[i], i + 1)) {
        s.push_back('+');
        return true;
    } else if (solve(r * a[i], i + 1)) {
        s.push_back('*');
        return true;
    } else {
        return false;
    }

} 

int main() {
    std::cin >> n >> t;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    int r = a[0];
    if(!solve(r, 1)) {
        return 1;
    }
    std::cout << s << std::endl;

}
0