結果

問題 No.265 数学のテスト
ユーザー maimai
提出日時 2017-12-31 09:24:22
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 890 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 11,452 KB
実行使用メモリ 30,136 KB
最終ジャッジ日時 2023-08-23 12:21:33
合計ジャッジ時間 6,484 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 125 ms
22,084 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 TLE -
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:29: warning: assigned but unused variable - x
Syntax OK

ソースコード

diff #

class Nyan
    attr_accessor :e
    def initialize(h={1=> 1})
        @e = h # 次数=>係数,
        return self
    end
    def *(z)
        y = self.clone
        h = {}
        z.e.each do |a|
            y.e.each do |b|
                d = a[0]+b[0]
                h[d] = h[d].to_i + a[1]*b[1]
            end
        end
        y.e = h
        return y
    end
    def +(z)
        y = self.clone
        z.e.each do |a|
            y.e[a[0]] = y.e[a[0]].to_i + a[1]
        end
        return y
    end
end


x = Nyan.new
def d(w)
    h={}
    w.e.each do |d,k|
        h[d-1] = k*d if d>0
    end
    r = Nyan.new
    r.e = h
    return r
end


gets
m = gets.to_i
str = gets.chomp

str.gsub!(/[0-9]+/,'Nyan.new(0=>\0)')
str.gsub!('{','(')
str.gsub!('}',')')
str.gsub!(/x(:?\*x)+/){|mat| "Nyan.new(#{(mat.size+1)/2}=>1)"}

ans = eval(str)

puts (0..m).map{|e| ans.e[e].to_i}*" "

0