結果
問題 | No.1150 シュークリームゲーム(Easy) |
ユーザー |
|
提出日時 | 2020-08-07 23:15:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 103 ms / 2,000 ms |
コード長 | 1,183 bytes |
コンパイル時間 | 283 ms |
コンパイル使用メモリ | 82,260 KB |
実行使用メモリ | 97,752 KB |
最終ジャッジ日時 | 2024-09-25 00:00:48 |
合計ジャッジ時間 | 4,529 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 43 |
ソースコード
#!/usr/bin/env pypy3N=int(input())s, t = input().split()s = int(s)t = int(t)s -= 1t -= 1A = list(map(int, input().split()))assert(len(A) == N)q1 = []i = (s+1) % Nwhile i != t:q1 += [A[i]]i += 1i %= Nq2 = []i = (s-1) % Nwhile i != t:q2 += [A[i]]i -= 1i %= Nfrom functools import lru_cache@lru_cache(None)def ans(q1, q2):if len(q1) == 0 and len(q2) == 0: return 0if len(q1) % 2 == 0 and len(q2) % 2 == 0:m1 = len(q1) // 2m2 = len(q2) // 2return sum(q1[:m1]) - sum(q1[m1:]) + sum(q2[:m2]) - sum(q2[m2:])if len(q1) % 2 == 1 and len(q2) % 2 == 1:m1 = len(q1) // 2m2 = len(q2) // 2return max(sum(q1[:m1+1]) - sum(q1[m1+1:]) + sum(q2[:m2]) - sum(q2[m2:]),sum(q1[:m1]) - sum(q1[m1:]) + sum(q2[:m2+1]) - sum(q2[m2+1:]))if len(q1) == 0:qh, *qt = q2return qh - ans(q1[::-1], tuple(qt)[::-1])if len(q2) == 0:qh, *qt = q1return qh - ans(tuple(qt)[::-1], q2[::-1])q1h, *q1t = q1q2h, *q2t = q2return max(q2h - ans(q1[::-1], tuple(q2t)[::-1]),q1h - ans(tuple(q1t)[::-1], q2[::-1]))# print(ans((100, 100, 100, 3, 2, 1), (1, 2, 100, 100)))print(A[s] - A[t] + ans(tuple(q1), tuple(q2)))