Submission #8902642


Source Code Expand

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace std;

const int maxn = 2005;

int dp[2][maxn][maxn];
int suf[2][maxn][maxn];
int n, z, w;
int a[maxn];

int main(){
    cin >> n >> z >> w;
    for(int i = 1;i <= n;i++){
        scanf("%d", &a[i]);
    } 
    a[0] = w;
    for(int j = n;j >= 1;j--){
        for(int i = j - 1;i >= 0;i--){
            for(int k = 0;k < 2;k++){
                if(j == n){
                    dp[k][i][j] = abs(a[i] - a[j]);
                    suf[k][i][j] = dp[k][i][j];
                }else{
                    dp[k][i][j] = suf[k ^ 1][j][j + 1];
                    if(k == 0){
                        suf[k][i][j] = max(suf[k][i][j + 1], dp[k][i][j]);
                    }else{
                        suf[k][i][j] = min(suf[k][i][j + 1], dp[k][i][j]);
                    }
                }
            }
        }
    }
    int ans = 0;
    for(int i = 1;i <= n;i++){
        ans = max(ans, dp[0][0][i]);
    }
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task D - ABS
User Yufan_Huang
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1101 Byte
Status AC
Exec Time 91 ms
Memory 62464 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:18:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
                           ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 4
AC × 28
Set Name Test Cases
Sample example_0, example_1, example_2, example_3
All example_0, example_1, example_2, example_3, one_0, one_1, one_2, one_3, one_4, one_5, one_6, one_7, rand_0, rand_1, rand_10, rand_11, rand_12, rand_13, rand_14, rand_15, rand_2, rand_3, rand_4, rand_5, rand_6, rand_7, rand_8, rand_9
Case Name Status Exec Time Memory
example_0 AC 2 ms 6400 KB
example_1 AC 2 ms 6400 KB
example_2 AC 2 ms 6400 KB
example_3 AC 2 ms 6400 KB
one_0 AC 2 ms 6400 KB
one_1 AC 2 ms 6400 KB
one_2 AC 2 ms 6400 KB
one_3 AC 2 ms 6400 KB
one_4 AC 2 ms 6400 KB
one_5 AC 2 ms 6400 KB
one_6 AC 2 ms 6400 KB
one_7 AC 2 ms 6400 KB
rand_0 AC 89 ms 62336 KB
rand_1 AC 9 ms 26368 KB
rand_10 AC 89 ms 62464 KB
rand_11 AC 14 ms 34816 KB
rand_12 AC 90 ms 62336 KB
rand_13 AC 65 ms 59648 KB
rand_14 AC 91 ms 62464 KB
rand_15 AC 3 ms 11264 KB
rand_2 AC 91 ms 62464 KB
rand_3 AC 64 ms 59648 KB
rand_4 AC 90 ms 62464 KB
rand_5 AC 22 ms 41216 KB
rand_6 AC 90 ms 62464 KB
rand_7 AC 27 ms 45312 KB
rand_8 AC 91 ms 62336 KB
rand_9 AC 66 ms 59648 KB