結果
問題 |
No.1150 シュークリームゲーム(Easy)
|
ユーザー |
![]() |
提出日時 | 2022-12-15 23:11:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 67 ms / 2,000 ms |
コード長 | 1,008 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 81,988 KB |
実行使用メモリ | 88,468 KB |
最終ジャッジ日時 | 2024-11-14 14:46:29 |
合計ジャッジ時間 | 4,783 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 43 |
ソースコード
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)