結果

問題 No.1021 Children in Classrooms
ユーザー 小野寺健小野寺健
提出日時 2021-11-06 15:44:37
言語 Ruby
(3.3.0)
結果
AC  
実行時間 343 ms / 2,000 ms
コード長 680 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 40,576 KB
最終ジャッジ日時 2024-04-25 03:21:44
合計ジャッジ時間 6,601 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
12,160 KB
testcase_01 AC 90 ms
12,288 KB
testcase_02 AC 94 ms
12,160 KB
testcase_03 AC 103 ms
12,288 KB
testcase_04 AC 105 ms
12,416 KB
testcase_05 AC 101 ms
12,288 KB
testcase_06 AC 98 ms
12,160 KB
testcase_07 AC 99 ms
12,416 KB
testcase_08 AC 98 ms
12,416 KB
testcase_09 AC 339 ms
40,576 KB
testcase_10 AC 343 ms
40,320 KB
testcase_11 AC 342 ms
40,576 KB
testcase_12 AC 338 ms
38,656 KB
testcase_13 AC 332 ms
38,656 KB
testcase_14 AC 335 ms
38,656 KB
testcase_15 AC 265 ms
30,848 KB
testcase_16 AC 266 ms
30,976 KB
testcase_17 AC 270 ms
31,104 KB
testcase_18 AC 281 ms
31,360 KB
testcase_19 AC 191 ms
27,008 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split(" ").map{|s| s.to_i}
a = gets.split(" ").map{|s| s.to_i}
S = gets.strip.split("")

lindex = 0
rindex = N-1
ln = rn = 1

S.each {|c|
	if c == "L" then
		ln += 1 if lindex == 0 and ln < N
		lindex -= 1 if lindex > 0
		rindex -= 1 if rindex > 0
	else
		rn += 1 if rindex == N-1 and rn < N
		rindex += 1 if rindex < N - 1
		lindex += 1 if lindex < N - 1
	end
}

ans = ""
ans += "0 " * lindex

if rindex == lindex then
	ans += a.sum.to_s
elsif ln + rn == N then
	ans += a[0, ln].sum.to_s + " " + a[N-rn, rn].sum.to_s
else
	ans += a[0, ln].sum.to_s + + " " + a[ln,N-ln-rn].map{|i| i.to_s}.join(" ") + " " + a[N-rn, rn].sum.to_s
end
ans += " 0" * (N-1-rindex)

puts ans
0