結果

問題 No.505 カードの数式2
ユーザー DameningenDameningen
提出日時 2017-04-21 23:15:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,528 bytes
コンパイル時間 1,069 ms
コンパイル使用メモリ 86,896 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 23:17:19
合計ジャッジ時間 2,086 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<cstring>
#include<sstream>
#include<cassert>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main()
{
    int n;
    static int a[16];
    cin >> n;
    rep(i, n) {
        cin >> a[i];
    }
    
    static int dp[16][2];
    dp[0][0] = a[0];
    for (int i = 1; i < n; ++i) {
        dp[i][0] = min(dp[i][0], dp[i-1][0] + a[i]);
        dp[i][0] = min(dp[i][0], dp[i-1][0] - a[i]);
        dp[i][0] = min(dp[i][0], dp[i-1][0] * a[i]);
        dp[i][0] = min(dp[i][0], dp[i-1][1] + a[i]);
        dp[i][0] = min(dp[i][0], dp[i-1][1] - a[i]);
        dp[i][0] = min(dp[i][0], dp[i-1][1] * a[i]);
        
        dp[i][1] = max(dp[i][1], dp[i-1][0] + a[i]);
        dp[i][1] = max(dp[i][1], dp[i-1][0] - a[i]);
        dp[i][1] = max(dp[i][1], dp[i-1][0] * a[i]);
        dp[i][1] = max(dp[i][1], dp[i-1][1] + a[i]);
        dp[i][1] = max(dp[i][1], dp[i-1][1] - a[i]);
        dp[i][1] = max(dp[i][1], dp[i-1][1] * a[i]);
    }
    
    cout << dp[n-1][1] << endl;
    return 0;
}
0