Submission #2672279
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//
int N, Z, W;
int a[2000];
int dp[2000][2];
int dfs(int idx, int turn) {
if (~dp[idx][turn]) return dp[idx][turn];
int cur;
if (idx == 0) cur = !turn ? W : Z;
else cur = a[idx - 1];
int res;
if (turn == 0) {
res = 0;
FOR(i, idx, N - 1) chmax(res, dfs(i + 1, turn^1));
chmax(res, abs(cur - a[N - 1]));
}
else {
res = INF;
FOR(i, idx, N - 1) chmin(res, dfs(i + 1, turn^1));
chmin(res, abs(cur - a[N - 1]));
}
return dp[idx][turn] = res;
}
int main() {
cin >> N >> Z >> W;
REP(i, N) scanf("%d", a + i);
memset(dp, -1, sizeof(dp));
cout << dfs(0, 0) << endl;
return 0;
}
Submission Info
Submission Time
2018-06-16 12:49:27+0900
Task
D - ABS
User
tkmst201
Language
C++14 (GCC 5.4.1)
Score
500
Code Size
1253 Byte
Status
AC
Exec Time
11 ms
Memory
384 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:46:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
REP(i, N) 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
256 KB
example_1
AC
1 ms
256 KB
example_2
AC
1 ms
256 KB
example_3
AC
1 ms
256 KB
one_0
AC
1 ms
256 KB
one_1
AC
1 ms
256 KB
one_2
AC
1 ms
256 KB
one_3
AC
1 ms
256 KB
one_4
AC
1 ms
256 KB
one_5
AC
1 ms
256 KB
one_6
AC
1 ms
256 KB
one_7
AC
1 ms
256 KB
rand_0
AC
11 ms
384 KB
rand_1
AC
2 ms
256 KB
rand_10
AC
11 ms
384 KB
rand_11
AC
3 ms
256 KB
rand_12
AC
11 ms
384 KB
rand_13
AC
8 ms
384 KB
rand_14
AC
11 ms
384 KB
rand_15
AC
1 ms
256 KB
rand_2
AC
11 ms
384 KB
rand_3
AC
8 ms
384 KB
rand_4
AC
11 ms
384 KB
rand_5
AC
4 ms
384 KB
rand_6
AC
11 ms
384 KB
rand_7
AC
5 ms
384 KB
rand_8
AC
11 ms
384 KB
rand_9
AC
8 ms
384 KB