結果

問題 No.10 +か×か
ユーザー kyunakyuna
提出日時 2020-05-02 01:05:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 775 bytes
コンパイル時間 773 ms
コンパイル使用メモリ 78,008 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-21 06:29:31
合計ジャッジ時間 3,050 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
template<class T> inline bool chmax(T &a, T b) { return a < b ? (a = b, 1) : 0; }

int main() {
    assert("*" < "+" && "+" < "@");
    int n; cin >> n;
    int total; cin >> total;
    vector<int> a(n);
    for (auto &ai: a) cin >> ai;
    vector<vector<string>> dp(n, vector<string>(total + 1));
    dp[0][a[0]] = "@";
    for (int i = 0; i + 1 < n; i++) for (int j = 0; j <= total; j++) {
        if (j + a[i + 1] <= total) {
            chmax(dp[i + 1][j + a[i + 1]], dp[i][j] + "+");
        }
        if (j * a[i + 1] <= total) {
            chmax(dp[i + 1][j * a[i + 1]], dp[i][j] + "*");
        }
    }
    cout << dp.back()[total].substr(1) << endl;
    return 0;
}
0