Submission #5548128
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2005;
int A[N];
ll dp[N][N][2];
ll solveDp(int ind,int prev,int bit,int n) {
if(ind==n) {
int r = 1;
if(bit==0) {
r = -1;
}
return r*abs(A[ind]-A[prev]);
}
ll &ret= dp[ind][prev][bit];
if(ret!=-1) {
return ret;
}
ret = solveDp(ind+1,prev,bit,n);
ret= max(ret, -solveDp(ind+1,ind,bit^1,n));
return ret;
}
void solve() {
int n;
scanf("%d",&n);
n+=2;
for(int i=1;i<=n;++i) {
scanf("%d",&A[i]);
}
memset(dp,-1,sizeof(dp));
printf("%lld\n", solveDp(3,2,1,n));
}
int main() {
//freopen("input.txt","r",stdin);
solve();
}
Submission Info
Submission Time
2019-05-23 00:07:37+0900
Task
D - ABS
User
ffresh
Language
C++14 (GCC 5.4.1)
Score
500
Code Size
766 Byte
Status
AC
Exec Time
82 ms
Memory
63104 KB
Compile Error
./Main.cpp: In function ‘void solve()’:
./Main.cpp:29:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:32:26: 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
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
17 ms
63104 KB
example_1
AC
17 ms
63104 KB
example_2
AC
17 ms
63104 KB
example_3
AC
17 ms
63104 KB
one_0
AC
17 ms
63104 KB
one_1
AC
17 ms
63104 KB
one_2
AC
17 ms
63104 KB
one_3
AC
17 ms
63104 KB
one_4
AC
17 ms
63104 KB
one_5
AC
17 ms
63104 KB
one_6
AC
17 ms
63104 KB
one_7
AC
17 ms
63104 KB
rand_0
AC
81 ms
63104 KB
rand_1
AC
24 ms
63104 KB
rand_10
AC
81 ms
63104 KB
rand_11
AC
29 ms
63104 KB
rand_12
AC
81 ms
63104 KB
rand_13
AC
64 ms
63104 KB
rand_14
AC
81 ms
63104 KB
rand_15
AC
18 ms
63104 KB
rand_2
AC
80 ms
63104 KB
rand_3
AC
64 ms
63104 KB
rand_4
AC
81 ms
63104 KB
rand_5
AC
37 ms
63104 KB
rand_6
AC
80 ms
63104 KB
rand_7
AC
42 ms
63104 KB
rand_8
AC
82 ms
63104 KB
rand_9
AC
65 ms
63104 KB