結果

問題 No.10 +か×か
ユーザー tokkakatokkaka
提出日時 2016-07-17 14:27:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,111 bytes
コンパイル時間 1,061 ms
コンパイル使用メモリ 98,492 KB
実行使用メモリ 14,008 KB
最終ジャッジ日時 2024-04-23 15:02:20
合計ジャッジ時間 7,394 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <functional>
#include <tuple>
#include <climits>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iomanip>

using namespace std;


enum Operation {
    sum = 0,
    product = 1
};

void next(std::vector<Operation> &op)
{
    for(int i=op.size()-1; i>=0 ;i--) {
        if(op[i]==sum) {
            op[i] = product;
            break;
        }
        op[i] = sum;
    }
}

std::vector<Operation> solve(std::vector<int> f, int total)
{
    std::vector<Operation> op(f.size()-1, sum);

    while(true) {
        int answer=f[0];
        for(int i=1;i<f.size();i++) {
            if(op[i-1] == sum) answer += f[i];
            else answer *= f[i];
        }
        if(answer == total) break;
        next(op);
    }

    return op;
}

int main()
{
    int N, Total;
    cin >> N;
    cin >> Total;
    vector<int> A(N);
    for(auto &a : A) cin >> a;
    auto op = solve(A, Total);
    for(const auto& o : op)
        cout << (o==sum?"+":"*");
    cout << endl;
}
0