結果

問題 No.1021 Children in Classrooms
ユーザー 学ぶマン
提出日時 2025-09-06 21:57:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 1,063 bytes
コンパイル時間 258 ms
コンパイル使用メモリ 82,596 KB
実行使用メモリ 106,892 KB
最終ジャッジ日時 2025-09-06 21:57:35
合計ジャッジ時間 4,416 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, math
sys.setrecursionlimit(10**8)
sys.set_int_max_str_digits(0)
INF = 10**18
MOD = 998244353
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import product, combinations, permutations, groupby, accumulate

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

pos = [0]

# 二人だけ位置を追う
a1, aN = 0, N - 1

for s in S:
    if s == 'L':
        pos.append(pos[-1] - 1)
        if a1 != 0:
            a1 -= 1
        if aN != 0:
            aN -= 1
    else:
        pos.append(pos[-1] + 1)
        if a1 != N - 1:
            a1 += 1
        if aN != N - 1:
            aN += 1

left = min(pos)
right = max(pos)
# 最終的な相対位置
memo = pos[-1]

ans = [0] * N
ans[a1] += A[0]
ans[aN] += A[-1]

for i in range(1, N - 1):

    #if 1 <= i <= left:
    if i + left <= 0:
        ans[a1] += A[i]
    
    #elif N - right <= i <= N - 2:
    elif i + right >= N - 1:
        ans[aN] += A[i]
    else:
        ans[i + memo] += A[i]

print(*ans)
0