結果

問題 No.10 +か×か
ユーザー drymousedrymouse
提出日時 2024-02-16 19:16:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,057 bytes
コンパイル時間 756 ms
コンパイル使用メモリ 71,208 KB
実行使用メモリ 10,004 KB
最終ジャッジ日時 2024-02-16 19:17:08
合計ジャッジ時間 7,726 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;

string plusORtimes(int A[], int l, int total) {
    string result;
    if (l == 1) {
        if (total == A[0]) {
            result = "";
        } else {
            result = "!";
        }
    } else if (total < 1) {
        result = "!";
    } else {
        if (total % A[l-1]) {
            result = plusORtimes(A, l - 1, total - A[l-1]) + "+";
        } else {
            string add = plusORtimes(A, l - 1, total - A[l-1]) + "+";
            string times = plusORtimes(A, l - 1, total / A[l-1]) + "*";
            int cmp = add.compare(times);
            if (cmp > 0) {
                result = add;
            } else {
                result = times;
            }
        }
    }
    //cout << "l: " << l << ", total: " << total << ", return " << result << endl;
    return result;
}

int main(void) {
    int N, Total;
    cin >> N >> Total;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    cout << plusORtimes(A, N, Total) << endl;
    
    return 0;
}
0