結果
| 問題 |
No.222 引き算と足し算
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-06-06 05:58:27 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 101 ms / 1,000 ms |
| コード長 | 865 bytes |
| コンパイル時間 | 466 ms |
| コンパイル使用メモリ | 7,296 KB |
| 実行使用メモリ | 12,544 KB |
| 最終ジャッジ日時 | 2024-11-15 21:30:36 |
| 合計ジャッジ時間 | 5,420 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
コンパイルメッセージ
Syntax OK
ソースコード
#!/usr/bin/ruby
#cf: http://qiita.com/cielavenir/items/cadbc5e24525b6a86cf8
begin
require 'iseq'
rescue LoadError
require 'fiddle'
class RubyVM
class InstructionSequence
addr = Fiddle.dlopen(nil)['rb_iseq_load']
fn = Fiddle::Function.new(addr, [Fiddle::TYPE_VOIDP] * 3, Fiddle::TYPE_VOIDP)
define_singleton_method(:load) do |dat, par=nil, opt=nil|
fn.call(Fiddle.dlwrap(dat), par, opt).to_value
end
end
end
end
while gets
bytecode=RubyVM::InstructionSequence.compile($_).to_a
bytecode[13].map!{|e|
if e[1].is_a?(Hash)&&e[1].has_key?(:mid)
e[1][:mid]=e[1][:mid].to_s.tr('+-','-+').to_sym
e[0]={:+ => :opt_plus,:- => :opt_minus}[e[1][:mid]]
end
e
}
p RubyVM::InstructionSequence.load(bytecode).eval
end