Submission #4032242
Source Code Expand
#include<cstdio>
#include<algorithm>
#include <cmath>
using namespace std;
using ll = long long;
int main(){
int N, Z, W;
scanf("%d %d %d", &N, &Z, &W);
int a[N + 1];
a[0] = W;
for (int i = 1; i <= N; ++i) scanf("%d", a + i);
int dp[4][N];
dp[0][N - 1] = 0;
dp[2][N - 1] = 1000000000;
dp[1][N - 1] = dp[3][N - 1] = abs(a[N] - a[N - 1]);
for (int i = N - 2; i >= 0; --i){
dp[0][i] = max(dp[0][i + 1], dp[3][i + 1]);
dp[1][i] = max(dp[0][i], abs(a[N] - a[i]));
dp[2][i] = min(dp[2][i + 1], dp[1][i + 1]);
dp[3][i] = min(dp[2][i], abs(a[N] - a[i]));
}
printf("%d\n", dp[1][0]);
return 0;
}
Submission Info
Submission Time
2019-01-17 22:49:00+0900
Task
D - ABS
User
boatmuscles
Language
C++14 (GCC 5.4.1)
Score
500
Code Size
632 Byte
Status
AC
Exec Time
1 ms
Memory
256 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:9:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &N, &Z, &W);
^
./Main.cpp:12:49: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
for (int i = 1; i <= N; ++i) 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
1 ms
128 KB
example_1
AC
1 ms
128 KB
example_2
AC
1 ms
128 KB
example_3
AC
1 ms
128 KB
one_0
AC
1 ms
128 KB
one_1
AC
1 ms
128 KB
one_2
AC
1 ms
128 KB
one_3
AC
1 ms
128 KB
one_4
AC
1 ms
128 KB
one_5
AC
1 ms
128 KB
one_6
AC
1 ms
128 KB
one_7
AC
1 ms
128 KB
rand_0
AC
1 ms
256 KB
rand_1
AC
1 ms
128 KB
rand_10
AC
1 ms
256 KB
rand_11
AC
1 ms
128 KB
rand_12
AC
1 ms
256 KB
rand_13
AC
1 ms
128 KB
rand_14
AC
1 ms
256 KB
rand_15
AC
1 ms
128 KB
rand_2
AC
1 ms
256 KB
rand_3
AC
1 ms
256 KB
rand_4
AC
1 ms
256 KB
rand_5
AC
1 ms
128 KB
rand_6
AC
1 ms
256 KB
rand_7
AC
1 ms
128 KB
rand_8
AC
1 ms
256 KB
rand_9
AC
1 ms
256 KB