結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー takakin
提出日時 2020-08-08 20:55:19
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 919 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 21,788 KB
最終ジャッジ日時 2024-10-02 03:44:33
合計ジャッジ時間 6,444 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 35 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
s,t=map(int,input().split())
A=[int(i) for i in input().split()]
sign=1
if s>t:
	s,t=t,s
	sign=-1

a,b=t-s-1,n-(t-s+1)
ans=0
s-=1
t-=1
if a%2==0 or b%2==0:
	for i in range(n):
		if i<=s:
			if s-i<=i+n-t:
				ans+=A[i]
			else:
				ans-=A[i]
		elif i<=t:
			if i-s<=t-i:
				ans+=A[i]
			else:
				ans-=A[i]
		else:
			if n+s-i<=i-t:
				ans+=A[i]
			else:
				ans-=A[i]
	print(sign*ans)
else:
	dif=0
	for i in range(n):
		if i<=s:
			if s-i<i+n-t:
				ans+=A[i]
			elif s-i==i+n-t:
				dif+=A[i]
			else:
				ans-=A[i]
		elif i<=t:
			if i-s<t-i:
				ans+=A[i]
			elif i-s==t-i:
				dif-=A[i]
			else:
				ans-=A[i]
		else:
			if n+s-i<i-t:
				ans+=A[i]
			elif n+s-i==i-t:
				dif+=A[i]
			else:
				ans-=A[i]
	if sign==1:
		if dif>=0:
			print(ans+dif)
		else:
			print(ans-dif)
	else:
		if dif>=0:
			print(-ans+dif)
		else:
			print(-ans-dif)
0