結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー KKT89KKT89
提出日時 2020-08-07 22:36:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,323 bytes
コンパイル時間 1,096 ms
コンパイル使用メモリ 113,708 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 03:18:15
合計ジャッジ時間 5,111 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,348 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,348 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int n;
ll a[100100];
int s,t;

ll dfs(int sl,int sr,int tl,int tr,ll f){
	ll res=0;
	if(f==1){
		int nsl=(sl-1+n)%n;
		if(nsl!=tl&&nsl!=tr){
			if(res==0)res=-1e18;
			res=max(res,dfs(nsl,sr,tl,tr,-f)+a[nsl]);
		}
		int nsr=(sr+1)%n;
		if(nsr!=tl&&nsr!=tr){
			if(res==0)res=-1e18;
			res=max(res,dfs(sl,nsr,tl,tr,-f)+a[nsr]);
		}
	}
	else{
		int ntl=(tl-1+n)%n;
		if(ntl!=sl&&ntl!=sr){
			if(res==0)res=1e18;
			res=min(res,dfs(sl,sr,ntl,tr,-f)-a[ntl]);
		}
		int ntr=(tr+1)%n;
		if(ntr!=sl&&ntr!=sr){
			if(res==0)res=-1e18;
			res=min(res,dfs(sl,sr,tl,ntr,-f)-a[ntr]);
		}
	}
	//cout << sl << " " << sr << " " << tl << " " << tr << " " << res << endl;
	return res;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n;
	cin >> s >> t;
	s--; t--;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	cout << dfs(s,s,t,t,1)+a[s]-a[t] << endl;
}
0