結果

問題 No.510 二次漸化式
ユーザー letrangerjpletrangerjp
提出日時 2017-04-29 00:10:08
言語 Ruby
(3.2.2)
結果
WA  
実行時間 -
コード長 633 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 11,292 KB
実行使用メモリ 19,500 KB
最終ジャッジ日時 2023-10-11 20:41:18
合計ジャッジ時間 15,247 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

N = gets.to_i
Q = gets.to_i
Query = Q.times.map{
  q,*args = gets.split
  [q.intern] + args.map(&:to_i)
}

$x = Hash.new(0)
$y = Hash.new(0)
$a = {}
$b = {}

def a(i)
  return 1 if i == 0
  # $a[i] ||= ($x[i-1] * b(i-1)**2 + a(i-1)) % (10**9+7)
  $a[i] ||= if $x[i-1] == 0
    a(i-1)
  else
    $x[i-1] * b(i-1)**2 + a(i-1)
  end % (10**9+7)
end

def b(i)
  return 1 if i == 0
  $b[i] ||= if $y[i-1] == 0
    1
  else
    b(i-1) + 1
  end
end

Query.each{|q, *args|
  case q
  when :a
    puts a(args[0]) % (10**9+7)
  when :x
    $x[args[0]] = args[1]
    $a.clear
  when :y
    $y[args[0]] = args[1]
    $a.clear; $b.clear
  end
}
0