結果
問題 |
No.265 数学のテスト
|
ユーザー |
![]() |
提出日時 | 2022-12-15 07:03:29 |
言語 | Ruby (3.4.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 868 bytes |
コンパイル時間 | 103 ms |
コンパイル使用メモリ | 7,680 KB |
実行使用メモリ | 35,456 KB |
最終ジャッジ日時 | 2024-11-09 00:29:18 |
合計ジャッジ時間 | 6,851 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 4 |
other | TLE * 1 -- * 31 |
コンパイルメッセージ
Syntax OK
ソースコード
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(' ')