結果

問題 No.314 ケンケンパ
ユーザー DaYuanChiDaYuanChi
提出日時 2021-01-26 20:29:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 1,000 ms
コード長 493 bytes
コンパイル時間 1,696 ms
コンパイル使用メモリ 163,400 KB
実行使用メモリ 26,708 KB
最終ジャッジ日時 2023-09-05 23:47:42
合計ジャッジ時間 3,027 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
26,632 KB
testcase_01 AC 3 ms
7,432 KB
testcase_02 AC 3 ms
7,364 KB
testcase_03 AC 3 ms
7,384 KB
testcase_04 AC 3 ms
7,436 KB
testcase_05 AC 2 ms
7,388 KB
testcase_06 AC 3 ms
7,436 KB
testcase_07 AC 3 ms
7,480 KB
testcase_08 AC 3 ms
7,588 KB
testcase_09 AC 3 ms
7,416 KB
testcase_10 AC 3 ms
7,448 KB
testcase_11 AC 2 ms
7,372 KB
testcase_12 AC 3 ms
7,492 KB
testcase_13 AC 2 ms
7,424 KB
testcase_14 AC 2 ms
7,520 KB
testcase_15 AC 3 ms
7,516 KB
testcase_16 AC 3 ms
7,628 KB
testcase_17 AC 4 ms
12,504 KB
testcase_18 AC 8 ms
19,700 KB
testcase_19 AC 11 ms
26,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll a[1000005];
ll b[1000005];
ll c[1000005];

ll const mod = 1e9+7;

int main(){
  int n; cin >> n;
  a[2] = 1; b[2] = 1; c[2] = 0;
  int ans = 0;
  if(n==1) ans = 1;
  if(n==2) ans = 2;
  if(n>=3){
    for(int i = 3; i <= n; i++){
      a[i] = (b[i-1]+c[i-1])%mod;
      b[i] = c[i-1]%mod;
      c[i] = a[i-1]%mod;
    }
    ans = (a[n] + b[n] + c[n])%mod;
    ans = (ans+mod)%mod;
  }
  cout << ans << endl;
  return 0;
}
0