結果

問題 No.10 +か×か
ユーザー maine_honzukimaine_honzuki
提出日時 2020-05-03 15:41:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 893 bytes
コンパイル時間 1,672 ms
コンパイル使用メモリ 166,836 KB
実行使用メモリ 20,932 KB
最終ジャッジ日時 2023-09-03 13:19:26
合計ジャッジ時間 2,576 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int memo[51][100010];
int main() {
    int N, Total, A[60];
    cin >> N >> Total;
    for (int i = 0; i < N; i++)
        cin >> A[i];
    memo[0][A[0]] = 1;
    for (int i = 1; i < N; i++) {
        for (int x = 0; x <= Total; x++) {
            if (memo[i - 1][x]) {
                if (A[i] + x <= Total) {
                    memo[i][x + A[i]] = 1;
                }
                if (A[i] * x <= Total && !memo[i][x * A[i]]) {
                    memo[i][x * A[i]] = 2;
                }
            }
        }
    }

    string ans;
    int tot = Total;
    for (int i = N - 1; i > 0; i--) {
        if (memo[i][tot] == 1) {
            ans.push_back('+');
            tot -= A[i];
        } else {
            ans.push_back('*');
            tot /= A[i];
        }
    }
    reverse(ans.end(), ans.begin());
    cout << ans << endl;
}
0