結果

問題 No.1021 Children in Classrooms
ユーザー simansiman
提出日時 2020-09-04 03:17:33
言語 Ruby
(3.3.0)
結果
AC  
実行時間 326 ms / 2,000 ms
コード長 640 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 11,492 KB
実行使用メモリ 33,332 KB
最終ジャッジ日時 2023-08-16 04:17:23
合計ジャッジ時間 7,876 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,096 KB
testcase_01 AC 83 ms
15,096 KB
testcase_02 AC 81 ms
15,132 KB
testcase_03 AC 86 ms
15,132 KB
testcase_04 AC 86 ms
15,156 KB
testcase_05 AC 86 ms
15,040 KB
testcase_06 AC 87 ms
15,100 KB
testcase_07 AC 87 ms
15,420 KB
testcase_08 AC 88 ms
15,344 KB
testcase_09 AC 308 ms
33,208 KB
testcase_10 AC 301 ms
33,220 KB
testcase_11 AC 304 ms
33,308 KB
testcase_12 AC 302 ms
33,160 KB
testcase_13 AC 305 ms
33,332 KB
testcase_14 AC 305 ms
33,324 KB
testcase_15 AC 281 ms
30,504 KB
testcase_16 AC 282 ms
30,528 KB
testcase_17 AC 290 ms
31,704 KB
testcase_18 AC 326 ms
33,020 KB
testcase_19 AC 142 ms
15,764 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
S = gets.chomp

idx = 0
zure = 0
min_idx = Float::INFINITY
max_idx = -Float::INFINITY

S.each_char do |s|
  if s == 'L'
    idx -= 1
    zure -= 1
  else
    idx += 1
    zure += 1
  end

  zure = 0 if zure < 0
  zure = N - 1 if N <= zure

  min_idx = idx if min_idx > idx
  max_idx = idx if max_idx < idx
end

min_idx.abs.times do
  if A.size >= 2
    a1, a2 = A.shift(2)
    A.unshift(a1 + a2)
  end
end

max_idx.times do
  if A.size >= 2
    a1, a2 = A.pop(2)
    A.push(a1 + a2)
  end
end

ans = Array.new(N, 0)

A.each do |a|
  ans[zure] = a
  zure += 1
end

puts ans.join(' ')
0