結果

問題 No.265 数学のテスト
ユーザー simansiman
提出日時 2022-12-15 07:03:29
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 868 bytes
コンパイル時間 48 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 38,848 KB
最終ジャッジ日時 2024-04-26 10:01:32
合計ジャッジ時間 6,776 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
d = gets.to_i
S = gets.chomp

def parse(line)
  n = line.size
  i = 0
  a = 0
  d = 0
  res = Hash.new(0)

  while i < n
    ch = line[i]

    case ch
    when 'd'
      l = 1
      r = 0
      j = i + 1

      while l != r
        j += 1

        case line[j]
        when '{'
          l += 1
        when '}'
          r += 1
        end
      end

      ret = parse(line[i + 2..j - 1])
      ret.each do |deg, e|
        next if deg == 0
        res[deg - 1] += e * deg
      end

      i = j + 1
    when 'x'
      d += 1
      a = 1 if a == 0

      i += 1
    when '*'
      i += 1
    when '+'
      res[d] += a

      d = 0
      a = 0
      i += 1
    when '{'
      i += 1
    else
      a += ch.to_i
      i += 1
    end
  end

  if a != 0 || d != 0
    res[d] += a
  end

  res
end

res = parse(S)

puts [*0..d].map { |i| res[i] }.join(' ')
0