結果

問題 No.505 カードの数式2
ユーザー nanophoto12nanophoto12
提出日時 2017-08-18 23:38:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,546 bytes
コンパイル時間 776 ms
コンパイル使用メモリ 95,144 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 17:48:07
合計ジャッジ時間 1,656 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:29:21: warning: overflow in conversion from ‘double’ to ‘int’ changes value from ‘1.0e+15’ to ‘2147483647’ [-Woverflow]
   29 | const int invalid = 1e15;
      |                     ^~~~

ソースコード

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];

const int invalid = 1e15;

void update(int i, ll value)
{
    if(dp[0][i+1] == invalid)
    {
        dp[0][i+1] = value;
    }
    else
    {
        dp[0][i+1] = max(dp[0][i+1], value);
    }
    if(dp[1][i+1] == invalid)
    {
        dp[1][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, invalid);
    dp[1].assign(n+1, invalid);
    update(0, v[0]);
    for(int i = 1;i < n;i++)
    {
        for(int j = 0;j < 2;j++)
        {
            auto p = dp[j][i];
            if(p != invalid)
            {
                update(i, p + v[i]);
                update(i, p - v[i]);
                update(i, p * v[i]);
                if(v[i] != 0)
                {
                    update(i, p / v[i]);
                }
            }
        }
    }
    if(dp[0][n] != invalid)
    {
        cout << dp[0][n] << endl;
        return 0;
    }
    cout << dp[1][n] << endl;
    return 0;
}
0