結果

問題 No.1021 Children in Classrooms
ユーザー もりをもりを
提出日時 2020-04-10 21:47:55
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 161 ms / 2,000 ms
コード長 969 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 87,332 KB
実行使用メモリ 115,508 KB
最終ジャッジ日時 2023-10-14 00:00:02
合計ジャッジ時間 4,294 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,180 KB
testcase_01 AC 75 ms
71,508 KB
testcase_02 AC 72 ms
71,364 KB
testcase_03 AC 85 ms
76,828 KB
testcase_04 AC 85 ms
76,784 KB
testcase_05 AC 85 ms
76,668 KB
testcase_06 AC 85 ms
76,828 KB
testcase_07 AC 86 ms
76,684 KB
testcase_08 AC 86 ms
77,088 KB
testcase_09 AC 154 ms
107,112 KB
testcase_10 AC 152 ms
106,708 KB
testcase_11 AC 153 ms
106,624 KB
testcase_12 AC 161 ms
107,176 KB
testcase_13 AC 158 ms
106,828 KB
testcase_14 AC 160 ms
106,648 KB
testcase_15 AC 136 ms
100,020 KB
testcase_16 AC 137 ms
100,244 KB
testcase_17 AC 133 ms
100,196 KB
testcase_18 AC 146 ms
115,508 KB
testcase_19 AC 90 ms
76,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

# [l, r]
l,r = 0,n-1
l_margin = 0
r_margin = 0

for com in s:
    if l == r:
        if com == 'L':
            if l_margin:
                l_margin -= 1
                r_margin += 1
        else:
            if r_margin:
                r_margin -= 1
                l_margin += 1
        continue

    if com == 'L':
        if l_margin:
            l_margin -= 1
            r_margin += 1
            continue
        if l + 1 >= n:
            continue
        a[l + 1] += a[l]
        a[l] = 0
        l += 1
        r_margin += 1
    else:
        if r_margin:
            r_margin -= 1
            l_margin += 1
            continue
        if r - 1 < 0:
            continue
        a[r - 1] += a[r]
        a[r] = 0
        r -= 1
        l_margin += 1
    # print(a, l, r, l_margin, r_margin)

res = [0] * l_margin
res += a[l:r+1]
res += [0] * r_margin
print(*res)
# print(l, r)
0