結果

問題 No.505 カードの数式2
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-04-22 00:14:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 914 bytes
コンパイル時間 1,546 ms
コンパイル使用メモリ 164,428 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-28 11:30:31
合計ジャッジ時間 2,915 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 WA -
testcase_14 AC 2 ms
4,380 KB
testcase_15 WA -
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)



typedef long long ll;
int N, A[20];
ll dp[20][2];
//-----------------------------------------------------------------------------------
int main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];

    rep(i, 0, N) rep(j, 0, 2) dp[i][j] = -(1LL << 60);

    dp[0][0] = dp[0][1] = A[0];
    rep(i, 1, N) rep(j, 0, 2) {
        dp[i][0] = max(dp[i][0], dp[i - 1][j] + A[i]);
        dp[i][0] = max(dp[i][0], dp[i - 1][j] - A[i]);
        dp[i][0] = max(dp[i][0], dp[i - 1][j] * A[i]);
        if(0 != A[i]) dp[i][0] = max(dp[i][0], dp[i - 1][j] / A[i]);

        dp[i][1] = min(dp[i][1], dp[i - 1][j] + A[i]);
        dp[i][1] = min(dp[i][1], dp[i - 1][j] - A[i]);
        dp[i][1] = min(dp[i][1], dp[i - 1][j] * A[i]);
        if (0 != A[i]) dp[i][1] = min(dp[i][1], dp[i - 1][j] / A[i]);
    }

    cout << dp[N - 1][0] << endl;
}
0