結果
| 問題 | No.510 二次漸化式 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-04-28 23:59:49 |
| 言語 | Ruby (4.0.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 505 bytes |
| 記録 | |
| コンパイル時間 | 168 ms |
| コンパイル使用メモリ | 7,296 KB |
| 実行使用メモリ | 21,408 KB |
| 最終ジャッジ日時 | 2024-09-13 18:44:23 |
| 合計ジャッジ時間 | 5,186 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | TLE * 1 -- * 33 |
コンパイルメッセージ
Syntax OK
ソースコード
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)
end
def b(i)
return 1 if i == 0
$b[i] ||= $y[i-1] * b(i-1) + 1
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
}