結果

問題 No.10 +か×か
ユーザー nukachanukacha
提出日時 2017-05-03 06:21:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 789 bytes
コンパイル時間 525 ms
コンパイル使用メモリ 72,236 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-12 05:45:35
合計ジャッジ時間 7,097 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

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::reverse(s.begin(), s.end());
    std::cout << s << std::endl;

}
0