結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー AEnAEn
提出日時 2022-12-15 23:11:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,008 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 87,040 KB
最終ジャッジ日時 2024-04-26 22:51:19
合計ジャッジ時間 4,953 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
51,840 KB
testcase_01 AC 44 ms
52,480 KB
testcase_02 AC 41 ms
51,840 KB
testcase_03 AC 40 ms
51,968 KB
testcase_04 AC 41 ms
52,224 KB
testcase_05 AC 41 ms
51,968 KB
testcase_06 AC 40 ms
52,352 KB
testcase_07 AC 40 ms
52,224 KB
testcase_08 AC 41 ms
52,096 KB
testcase_09 AC 41 ms
51,840 KB
testcase_10 AC 41 ms
51,968 KB
testcase_11 AC 40 ms
51,968 KB
testcase_12 AC 40 ms
51,968 KB
testcase_13 AC 40 ms
52,224 KB
testcase_14 AC 41 ms
51,840 KB
testcase_15 AC 41 ms
52,096 KB
testcase_16 AC 40 ms
52,096 KB
testcase_17 AC 41 ms
51,968 KB
testcase_18 AC 41 ms
52,224 KB
testcase_19 AC 41 ms
52,096 KB
testcase_20 AC 41 ms
52,224 KB
testcase_21 AC 42 ms
52,096 KB
testcase_22 AC 71 ms
83,200 KB
testcase_23 AC 71 ms
83,584 KB
testcase_24 AC 69 ms
81,024 KB
testcase_25 AC 71 ms
83,072 KB
testcase_26 AC 74 ms
86,272 KB
testcase_27 AC 75 ms
86,528 KB
testcase_28 AC 76 ms
86,912 KB
testcase_29 AC 70 ms
82,944 KB
testcase_30 AC 72 ms
84,352 KB
testcase_31 AC 70 ms
83,712 KB
testcase_32 AC 72 ms
83,200 KB
testcase_33 AC 73 ms
84,480 KB
testcase_34 AC 75 ms
86,272 KB
testcase_35 AC 73 ms
86,528 KB
testcase_36 AC 74 ms
86,784 KB
testcase_37 AC 74 ms
87,040 KB
testcase_38 AC 70 ms
82,944 KB
testcase_39 AC 72 ms
83,200 KB
testcase_40 AC 71 ms
83,968 KB
testcase_41 AC 84 ms
86,656 KB
testcase_42 AC 72 ms
84,992 KB
testcase_43 AC 71 ms
84,608 KB
testcase_44 AC 74 ms
83,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
s, t = map(int, input().split())
s-=1;t-=1
a = list(map(int, input().split()))
sm = sum(a)
if (s+1)%N==t:
    b2 = 0
    for i in range(N//2):
        b2 += a[(t+i)%N]
    print(sm-2*b2)
    exit()
if (t+1)%N==s:
    b1 = 0
    for i in range((N+1)//2):
        b1 += a[(s+i)%N]
    print(2*b1-sm)
    exit()

a = a+a
if s<t:
    n1 = a[s+1:t]
    n2 = a[t+1:s+N]
    n3 = n1[::-1]
    n4 = n2[::-1]
    l1, l2 = len(n1), len(n2)
    p = a[s]+sum(n1[:l1//2])+sum(n4[:l2//2])
    q = a[t]+sum(n3[:l1//2:])+sum(n2[:l2//2])
else:
    n1 = a[t+1:s]
    n2 = a[s+1:t+N]
    n3 = n1[::-1]
    n4 = n2[::-1]
    l1, l2 = len(n1), len(n2)
    p = a[s]+sum(n2[:l2//2])+sum(n3[:l1//2])
    q = a[t]+sum(n4[:l2//2])+sum(n1[:l1//2])

if len(n1)%2==0 and len(n2)%2==0:
    print(p-q)
elif len(n1)%2==1 and len(n2)%2==1:
    p += max(n1[len(n1)//2],n2[len(n2)//2])
    q += min(n1[len(n1)//2],n2[len(n2)//2])
    print(p-q)
else:
    m = n1[len(n1)//2] if len(n1)%2==1 else n2[len(n2)//2]
    print(p+m-q)
0