結果

問題 No.505 カードの数式2
ユーザー nanophoto12
提出日時 2017-08-18 23:25:20
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,088 bytes
コンパイル時間 782 ms
コンパイル使用メモリ 94,924 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-14 15:01:55
合計ジャッジ時間 1,980 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> t3;

using namespace std;

vector<ll> dp[2];

void update(int i, ll value)
{
    if(value >= 0)
    {
        dp[0][i+1] = max(dp[0][i+1], value);
    }
    else
    {
        dp[1][i+1] = min(dp[1][i+1], value);
    }
}

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0;i < n;i++)
    {
        cin >> v[i];
    }
    dp[0].assign(n+1, 0);
    dp[1].assign(n+1, 0);
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < 2;j++)
        {
            auto p = dp[j][i];
            update(i, p + v[i]);
            update(i, p - v[i]);
            update(i, p * v[i]);
        }
    }
    cout << dp[0][n] << endl;
    return 0;
}
0