結果

問題 No.1021 Children in Classrooms
ユーザー nehan_der_thalnehan_der_thal
提出日時 2020-04-10 22:05:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 960 bytes
コンパイル時間 728 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 107,356 KB
最終ジャッジ日時 2023-10-14 00:37:01
合計ジャッジ時間 4,879 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,136 KB
testcase_01 WA -
testcase_02 AC 71 ms
71,300 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def bsearch(mn, mx, func):
    idx = (mx + mn)//2
    while mx-mn>1:
        if not func(idx):
            idx, mx = (idx + mn)//2, idx
            continue
        idx, mn = (idx + mx)//2, idx
    return idx

N, M = map(int, input().split())
A = list(map(int, input().split()))
S = input().strip()

def f(i):
    if i == 0:
        return 2
    elif i == N-1:
        return 1
    for c in S:
        if c == "R":
            i = min(i+1, N-1)
        else:
            i = max(i-1, 0)
        if i == 0:
            return 2
        if i == N-1:
            return 1
    return 0

def g(i):
    for c in S:
        if c == "R":
            i = min(i+1, N-1)
        else:
            i = max(i-1, 0)
    return i

#print(f(2))
u = bsearch(-1, N, lambda i : f(i) == 2)
v = bsearch(-1, N, lambda i : f(i) != 1)
s1, s2 = sum(A[:u+1]), sum(A[v+1:])
#print(s1, s2)
R = [0] * N
R[g(u)] = s1
R[g(v+1)] = s2
for i in range(g(u)+1, g(v+1)):
    R[i] = A[i]
print(*R)
0