結果
問題 | No.1433 Two color sequence |
ユーザー | terasa |
提出日時 | 2022-06-05 11:40:14 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 343 ms / 2,000 ms |
コード長 | 2,347 bytes |
コンパイル時間 | 225 ms |
コンパイル使用メモリ | 82,404 KB |
実行使用メモリ | 116,464 KB |
最終ジャッジ日時 | 2024-09-21 04:08:17 |
合計ジャッジ時間 | 8,321 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
55,276 KB |
testcase_01 | AC | 42 ms
55,708 KB |
testcase_02 | AC | 41 ms
56,112 KB |
testcase_03 | AC | 278 ms
113,972 KB |
testcase_04 | AC | 271 ms
113,572 KB |
testcase_05 | AC | 39 ms
56,196 KB |
testcase_06 | AC | 39 ms
55,896 KB |
testcase_07 | AC | 40 ms
54,976 KB |
testcase_08 | AC | 251 ms
116,464 KB |
testcase_09 | AC | 298 ms
114,288 KB |
testcase_10 | AC | 311 ms
112,480 KB |
testcase_11 | AC | 279 ms
113,768 KB |
testcase_12 | AC | 303 ms
114,308 KB |
testcase_13 | AC | 283 ms
114,528 KB |
testcase_14 | AC | 304 ms
115,004 KB |
testcase_15 | AC | 304 ms
115,024 KB |
testcase_16 | AC | 304 ms
115,124 KB |
testcase_17 | AC | 328 ms
114,900 KB |
testcase_18 | AC | 310 ms
114,936 KB |
testcase_19 | AC | 330 ms
114,680 KB |
testcase_20 | AC | 308 ms
114,696 KB |
testcase_21 | AC | 304 ms
115,008 KB |
testcase_22 | AC | 307 ms
115,228 KB |
testcase_23 | AC | 343 ms
114,928 KB |
ソースコード
import sys import pypyjit import itertools import heapq import math from collections import deque, defaultdict import bisect input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) pypyjit.set_param('max_unroll_recursion=-1') def index_lt(a, x): 'return largest index s.t. A[i] < x or -1 if it does not exist' return bisect.bisect_left(a, x) - 1 def index_le(a, x): 'return largest index s.t. A[i] <= x or -1 if it does not exist' return bisect.bisect_right(a, x) - 1 def index_gt(a, x): 'return smallest index s.t. A[i] > x or len(a) if it does not exist' return bisect.bisect_right(a, x) def index_ge(a, x): 'return smallest index s.t. A[i] >= x or len(a) if it does not exist' return bisect.bisect_left(a, x) class SegTree: def __init__(self, N, func, e): self.N = N self.func = func self.X = [e] * (N << 1) self.e = e def build(self, seq): for i in range(self.N): self.X[self.N + i] = seq[i] for i in range(self.N)[::-1]: self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1]) def add(self, i, x): i += self.N self.X[i] += x while i > 1: i >>= 1 self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1]) def update(self, i, x): i += self.N self.X[i] = x while i > 1: i >>= 1 self.X[i] = self.func(self.X[i << 1], self.X[i << 1 | 1]) def query(self, L, R): L += self.N R += self.N vL = self.e vR = self.e while L < R: if L & 1: vL = self.func(vL, self.X[L]) L += 1 if R & 1: R -= 1 vR = self.func(self.X[R], vR) L >>= 1 R >>= 1 return self.func(vL, vR) N = int(input()) T = input()[:-1] A = list(map(int, input().split())) A = [A[i] if T[i] == 'R' else -A[i] for i in range(N)] S = [0] * N S[0] = A[0] for i in range(1, N): S[i] = S[i - 1] + A[i] INF = 1 << 30 stmin = SegTree(N, min, INF) stmax = SegTree(N, max, -INF) stmin.build(S) stmax.build(S) ans = -INF for i in range(N): ma = stmax.query(i, N) mi = stmin.query(i, N) s = S[i - 1] if i > 0 else 0 ans = max(ans, ma - s) ans = max(ans, -(mi - s)) print(ans)