結果

問題 No.492 IOI数列
ユーザー koyumeishikoyumeishi
提出日時 2017-03-10 23:25:29
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 1,205 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 11,428 KB
実行使用メモリ 15,360 KB
最終ジャッジ日時 2023-09-06 14:18:16
合計ジャッジ時間 3,634 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 81 ms
15,120 KB
testcase_02 AC 80 ms
15,068 KB
testcase_03 AC 82 ms
15,052 KB
testcase_04 AC 82 ms
15,044 KB
testcase_05 AC 82 ms
15,212 KB
testcase_06 AC 82 ms
15,120 KB
testcase_07 AC 82 ms
15,056 KB
testcase_08 AC 82 ms
15,040 KB
testcase_09 AC 83 ms
15,136 KB
testcase_10 AC 82 ms
15,164 KB
testcase_11 AC 82 ms
15,168 KB
testcase_12 AC 82 ms
15,360 KB
testcase_13 AC 82 ms
15,232 KB
testcase_14 AC 82 ms
15,272 KB
testcase_15 AC 81 ms
15,036 KB
testcase_16 AC 81 ms
15,096 KB
testcase_17 AC 81 ms
15,264 KB
testcase_18 AC 81 ms
15,048 KB
testcase_19 AC 83 ms
15,040 KB
testcase_20 AC 84 ms
15,224 KB
testcase_21 AC 83 ms
15,212 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

mod1 = 10**9 + 7
mod2 = 101010101010101010101


n = gets.to_i

if n == 1 then
  puts 0
else
  m = n
  n = m-1
  res = [1,0,0,1]

  mat = [100,1,0,1]
  while n != 0 do 
    if( n%2 == 1 ) then
      res = [ mat[0] * res[0] + mat[1] * res[2], mat[0] * res[1] + mat[1] * res[3],
              mat[2] * res[0] + mat[3] * res[2], mat[2] * res[1] + mat[3] * res[3] ]
      res = res.map{|x| x % mod1 }
    end
    mat = [ mat[0] * mat[0] + mat[1] * mat[2], mat[0] * mat[1] + mat[1] * mat[3],
             mat[2] * mat[0] + mat[3] * mat[2], mat[2] * mat[1] + mat[3] * mat[3] ]
    mat = mat.map{|x| x%mod1 }
    n /= 2
  end
  puts (res[0] + res[1]) % mod1


  n = m-1
  res = [1,0,0,1]
  mat = [100,1,0,1]
  while n != 0 do 
    if( n%2 == 1 ) then
      res = [ mat[0] * res[0] + mat[1] * res[2], mat[0] * res[1] + mat[1] * res[3],
              mat[2] * res[0] + mat[3] * res[2], mat[2] * res[1] + mat[3] * res[3] ]
      res = res.map{|x| x % mod2 }
    end
    mat = [ mat[0] * mat[0] + mat[1] * mat[2], mat[0] * mat[1] + mat[1] * mat[3],
             mat[2] * mat[0] + mat[3] * mat[2], mat[2] * mat[1] + mat[3] * mat[3] ]
    mat = mat.map{|x| x%mod2 }
    n /= 2
  end
  puts (res[0] + res[1]) % mod2
end
0