Submission #3948451


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/











int N; ll A[3010];
//---------------------------------------------------------------------------------------------------
int vis[3010][3010];
ll memo[3010][3010];
ll dp(int L, int R) {
    if (L > R) return 0;
    if (vis[L][R]) return memo[L][R];
    vis[L][R] = 1;

    int diff = N - (R - L + 1);

    ll res = 0;
    if (diff % 2 == 0) {
        // X-Yを最大化したい
        res = -infl;
        chmax(res, dp(L + 1, R) + A[L]);
        chmax(res, dp(L, R - 1) + A[R]);
    } else {
        // X-Yを最小化したい
        res = infl;
        chmin(res, dp(L + 1, R) - A[L]);
        chmin(res, dp(L, R - 1) - A[R]);
    }

    return memo[L][R] = res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];

    cout << dp(0, N - 1) << endl;
}

Submission Info

Submission Time
Task L - Deque
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2165 Byte
Status AC
Exec Time 62 ms
Memory 105472 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 19
Set Name Test Cases
All 0_00, 0_01, 0_02, 0_03, 0_04, 1_00, 1_01, 1_02, 1_03, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09, 1_10, 1_11, 1_12, 1_13
Case Name Status Exec Time Memory
0_00 AC 2 ms 2304 KB
0_01 AC 1 ms 2304 KB
0_02 AC 2 ms 2304 KB
0_03 AC 1 ms 2304 KB
0_04 AC 2 ms 2304 KB
1_00 AC 2 ms 2304 KB
1_01 AC 2 ms 2304 KB
1_02 AC 62 ms 105472 KB
1_03 AC 62 ms 105472 KB
1_04 AC 62 ms 105472 KB
1_05 AC 62 ms 105472 KB
1_06 AC 62 ms 105472 KB
1_07 AC 62 ms 105472 KB
1_08 AC 62 ms 105472 KB
1_09 AC 62 ms 105472 KB
1_10 AC 62 ms 105472 KB
1_11 AC 62 ms 105472 KB
1_12 AC 62 ms 105344 KB
1_13 AC 62 ms 105472 KB