結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー 沙耶花沙耶花
提出日時 2020-08-07 21:50:01
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,225 bytes
コンパイル時間 2,107 ms
コンパイル使用メモリ 206,072 KB
実行使用メモリ 5,392 KB
最終ジャッジ日時 2023-10-25 00:46:11
合計ジャッジ時間 4,655 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 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 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 38 ms
5,112 KB
testcase_23 AC 38 ms
5,032 KB
testcase_24 AC 36 ms
4,980 KB
testcase_25 AC 37 ms
5,012 KB
testcase_26 AC 42 ms
5,268 KB
testcase_27 AC 42 ms
5,360 KB
testcase_28 AC 43 ms
5,128 KB
testcase_29 AC 36 ms
4,856 KB
testcase_30 AC 39 ms
5,056 KB
testcase_31 AC 38 ms
5,296 KB
testcase_32 AC 38 ms
5,036 KB
testcase_33 AC 40 ms
5,056 KB
testcase_34 AC 41 ms
5,088 KB
testcase_35 AC 42 ms
5,216 KB
testcase_36 AC 43 ms
5,204 KB
testcase_37 AC 44 ms
5,392 KB
testcase_38 AC 37 ms
5,004 KB
testcase_39 AC 36 ms
5,120 KB
testcase_40 AC 39 ms
5,052 KB
testcase_41 AC 42 ms
5,104 KB
testcase_42 AC 33 ms
5,136 KB
testcase_43 AC 33 ms
5,136 KB
testcase_44 AC 48 ms
5,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000001

int main(){
	
	int N,S,T;
	cin>>N>>S>>T;
	S--;T--;
	
	vector<long long> A(N);
	for(int i=0;i<N;i++)cin>>A[i];
	
	vector<long long> L,R;
	
	for(int i=S+1;true;i=(i+1)%N){
		if(i==T)break;
		R.push_back(A[i]);
	}
	
	for(int i=(S-1+N)%N;true;i=(i-1+N)%N){
		if(i==T)break;
		L.push_back(A[i]);
	}
	
	long long t = A[S]-A[T];
	
	if(L.size()%2==1&&R.size()%2==0)swap(L,R);
	
	if(L.size()%2==0||R.size()%2==0){
		long long ans = t;
		for(int i=0;i<L.size();i++){
			if(i<(L.size()+1)/2)ans += L[i];
			else ans -= L[i];
		}
		for(int i=0;i<R.size();i++){
			if(i<(R.size()+1)/2)ans += R[i];
			else ans -= R[i];
		}
		cout<<ans<<endl;
	}
	else{
		long long x = t;
		long long y = t;
		for(int i=0;i<L.size();i++){
			if(i<(L.size()+1)/2)x += L[i];
			else x -= L[i];
		}
		for(int i=0;i<R.size();i++){
			if(i<(R.size()+1)/2)y += R[i];
			else y -= R[i];
		}
		for(int i=0;i<L.size();i++){
			if(i<(L.size())/2)y += L[i];
			else y -= L[i];
		}
		for(int i=0;i<R.size();i++){
			if(i<(R.size())/2)x += R[i];
			else x -= R[i];
		}
		
		cout<<max(x,y)<<endl;
	}
		
	
	return 0;
}
0