結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,140 KB
testcase_01 AC 70 ms
71,492 KB
testcase_02 AC 68 ms
71,324 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 90 ms
76,544 KB
testcase_08 AC 88 ms
76,764 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 187 ms
99,424 KB
testcase_16 AC 183 ms
99,700 KB
testcase_17 AC 189 ms
100,016 KB
testcase_18 AC 189 ms
107,132 KB
testcase_19 AC 80 ms
76,044 KB
権限があれば一括ダウンロードができます

ソースコード

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 1
    for c in S:
        if c == "R":
            i = min(i+1, N-1)
        else:
            i = max(i-1, 0)
        if i == 0:
            return 1
    return 0

def f2(i):
    if 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 == 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(f2(0))
u = bsearch(-1, N, lambda i : f(i) == 1)
v = bsearch(-1, N, lambda i : f2(i) != 1)
#print(u,v)
R = [0] * N
if u < v+1:
    s1, s2 = sum(A[:u+1]), sum(A[v+1:])
    R[g(u)] = s1
    R[g(v+1)] = s2
    for i in range(g(u)+1, g(v+1)):
        R[i] = A[i]
else:
    R[g(u)] = sum(A)
print(*R)
0