結果

問題 No.1021 Children in Classrooms
ユーザー 炭酸水炭酸水
提出日時 2022-05-17 22:09:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 329 ms / 2,000 ms
コード長 1,168 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 11,088 KB
実行使用メモリ 32,312 KB
最終ジャッジ日時 2023-10-13 23:53:44
合計ジャッジ時間 4,990 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,288 KB
testcase_01 AC 17 ms
8,224 KB
testcase_02 AC 16 ms
8,224 KB
testcase_03 AC 19 ms
8,304 KB
testcase_04 AC 19 ms
8,216 KB
testcase_05 AC 20 ms
8,192 KB
testcase_06 AC 19 ms
8,252 KB
testcase_07 AC 21 ms
8,636 KB
testcase_08 AC 21 ms
8,620 KB
testcase_09 AC 283 ms
32,168 KB
testcase_10 AC 278 ms
32,312 KB
testcase_11 AC 277 ms
32,212 KB
testcase_12 AC 295 ms
32,160 KB
testcase_13 AC 292 ms
32,240 KB
testcase_14 AC 286 ms
32,124 KB
testcase_15 AC 265 ms
25,268 KB
testcase_16 AC 278 ms
26,340 KB
testcase_17 AC 275 ms
27,052 KB
testcase_18 AC 329 ms
31,120 KB
testcase_19 AC 141 ms
8,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int, input().split())
a = list(map(int, input().split()))
s = input()

l = 0
r = 0
L = 0
R = 0
count = 0
count_ex = 0
ex_sw = True
for i in range(m):
    if s[i] == "L":
        l += 1
        count -= 1
        count_ex -= 1
        if L < l - r:
            L = l - r
            count = 0
        if count_ex < 0:
            count_ex = 0
    elif s[i] == "R":
        r += 1
        count += 1
        count_ex += 1
        if R < r - l:
            R = r - l
        if count_ex > n - 1:
            count_ex = n - 1

    if L + R == n - 1 and ex_sw:
        ex_sw = False
        if s[i] == "L":
            count_ex = 0
        elif s[i] == "R":
            count_ex = n - 1

if ex_sw:
    ans_L = 0
    ans_R = 0
    for i in range(L + 1):
        ans_L += a[i]
    for i in range(n - R - 1, n):
        ans_R += a[i]
    ans = [0] * count 
    ans.append(ans_L)
    if L + 1 < n - R - 1:
        ans[count + 1:] = a[L + 1: n - R - 1]
    ans.append(ans_R)
    for _ in range(n - len(ans)):
        ans.append(0)
    print(*ans)

else:
    ans_sum = 0
    for i in a:
        ans_sum += i
    ans = [0] * n
    ans[count_ex] = ans_sum
    print(*ans)
0