結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー ryoissyryoissy
提出日時 2020-08-07 22:21:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,277 bytes
コンパイル時間 1,732 ms
コンパイル使用メモリ 175,028 KB
実行使用メモリ 5,912 KB
最終ジャッジ日時 2023-10-25 01:48:27
合計ジャッジ時間 3,783 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;

int n,s,t;
ll a[100005];
ll dp[100005];
vector<P> vec;

ll get_len(int p1,int p2){
	if(p1>p2)swap(p1,p2);
	return min(p2-p1,p1+n-p2);
}

int main(void){
	scanf("%d",&n);
	scanf("%d%d",&s,&t);
	s--;
	t--;
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	for(int i=0;i<n;i++){
		dp[i+1]+=dp[i]+a[i];
	}
	int cn=(n+1)/2;
	for(int i=1;i<=cn;i++){
		if(s<t){
			int ri=cn-i;
			if(t-s<i || (ri>=s && n-(ri-s)<=t))continue;
			ll val=dp[s+i];
			if(ri<=s){
				val-=dp[s-ri];
			}else{
				val+=dp[n]-dp[n-(ri-s)];
			}
			vec.push_back(P(val,i));
		}else{
			int ri=cn-i;
			if(s-t<=ri || (i+s-1>=n && (i-1+s-n)>=t))continue;
			ll val=-dp[s-ri];
			if(i+s<=n){
				val+=dp[i+s];
			}else{
				val+=dp[n]+dp[i+s-n];
			}
			vec.push_back(P(val,i));
		}
	}
	sort(vec.begin(),vec.end());
	reverse(vec.begin(),vec.end());
	for(int i=0;i<vec.size();i++){
		int li=s+vec[i].second-1;
		if(li>=n){
			li-=n;
		}
		int ri=s-(cn-vec[i].second);
		if(ri<0){
			ri+=n;
		}
		//printf("%d %d %d\n",li,ri,vec[i].second);
		if(vec[i].second<=get_len(t,li)+2 && (cn-vec[i].second)<=get_len(t,ri)+2){
			printf("%lld\n",vec[i].first*2LL-dp[n]);
			return 0;
		}
	}
	return 0;
}
0