結果

問題 No.891 隣接3項間の漸化式
ユーザー queeequeee
提出日時 2020-01-04 11:42:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 407 bytes
コンパイル時間 565 ms
コンパイル使用メモリ 63,872 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-05-02 07:58:36
合計ジャッジ時間 5,217 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 29 ms
5,376 KB
testcase_04 AC 57 ms
5,376 KB
testcase_05 AC 60 ms
5,376 KB
testcase_06 AC 77 ms
5,376 KB
testcase_07 AC 54 ms
5,376 KB
testcase_08 AC 49 ms
5,376 KB
testcase_09 AC 65 ms
5,376 KB
testcase_10 AC 13 ms
5,376 KB
testcase_11 AC 32 ms
5,376 KB
testcase_12 AC 91 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 59 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 8 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 10 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
typedef long long ll;

const ll mod = 1e9+7;

int main(void){
  // O(N)の嘘解法。通るかな?
  ll a,b,n; cin >>a>>b>>n;
  if (n<=1) {cout<<n<<endl; return 0;}
  ll p[3]={0,1, -1};
  p[2]=(b*p[0]+a*p[1])%mod;
  for(int i=0; i<n/3; i++) {
    p[0]=(b*p[1]+a*p[2])%mod;
    p[1]=(b*p[2]+a*p[0])%mod;
    p[2]=(b*p[0]+a*p[1])%mod;
  }
  
  cout<<p[n%3]<<endl;
}
0