結果

問題 No.505 カードの数式2
ユーザー toho_cake
提出日時 2017-04-22 10:12:04
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 585 bytes
コンパイル時間 458 ms
コンパイル使用メモリ 57,912 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-21 16:02:29
合計ジャッジ時間 1,373 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>

#define INF 114514191

using namespace std;

int N, a[20], dp[20];

int rec(int idx) {
    if(idx == 0) return a[0];
    if(dp[idx] != -INF) return dp[idx];

    int ret = -INF;
    int res = rec(idx - 1);

    if(a[idx] != 0) {
        ret = res / a[idx];
    }
    ret = max(ret, res + a[idx]);
    ret = max(ret, res - a[idx]);
    ret = max(ret, res * a[idx]);

    return dp[idx] = ret;
}

int main() {
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }

    fill_n(dp, 20, -INF);
    cout << rec(N - 1) << endl;
}
0