Submission #1798721


Source Code Expand

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define p(p) cout<<(p)<<" ";
#define pb push_back
#define mp make_pair
#define INF 1<<25

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef long long ll;

//int dy[8]={1,1,1,0,0,-1,-1,-1};
//int dx[8]={-1,0,1,-1,1,-1,0,1};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

struct S{
	int a,b,c;
};
bool asc(const S& left,const S& right){
	return left.c > right.c;
}
#define int ll
int N,M,Z,W;
vector<ll> a,b,c,d;
vector<vector<ll>> dp;

void input(){
	cin>>N>>Z>>W;
	a.resize(N+1);
	rep(i,N)cin>>a[i];
	dp.resize(N+1,vector<ll>(2,-1));
}

int dfs(int now,int turn){
	if(dp[now][turn]!=-1)return dp[now][turn];
	int other;
	if(now!=0) other=a[now-1];
	else other = W;
	if(now==N-1)return abs(a[N-1]-other);
	int res;
	if(turn){
		int mx=abs(other-a[N-1]);
		REP(i,now,N-1){
			int tmp=dfs(i+1,0);
			mx=max(mx,tmp);
		}
		res=mx;
	}
	else{
		int mn=abs(other-a[N-1]);
		REP(i,now,N-1){
			int tmp=dfs(i+1,1);
			mn=min(mn,tmp);
		}
		res=mn;
	}
	return dp[now][turn]=res;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	input();
	P(dfs(0,1))
	return 0;
}

Submission Info

Submission Time
Task D - ABS
User ke_to
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1749 Byte
Status AC
Exec Time 15 ms
Memory 512 KB

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 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 15 ms 512 KB
rand_1 AC 3 ms 384 KB
rand_10 AC 15 ms 512 KB
rand_11 AC 4 ms 384 KB
rand_12 AC 15 ms 512 KB
rand_13 AC 11 ms 512 KB
rand_14 AC 15 ms 512 KB
rand_15 AC 1 ms 256 KB
rand_2 AC 15 ms 512 KB
rand_3 AC 11 ms 512 KB
rand_4 AC 15 ms 512 KB
rand_5 AC 6 ms 384 KB
rand_6 AC 15 ms 512 KB
rand_7 AC 7 ms 384 KB
rand_8 AC 15 ms 512 KB
rand_9 AC 12 ms 512 KB