結果

問題 No.314 ケンケンパ
ユーザー KKT89KKT89
提出日時 2021-08-03 16:58:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 1,000 ms
コード長 761 bytes
コンパイル時間 2,746 ms
コンパイル使用メモリ 213,156 KB
実行使用メモリ 57,828 KB
最終ジャッジ日時 2023-10-14 21:09:22
合計ジャッジ時間 4,549 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
57,060 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 11 ms
8,468 KB
testcase_18 AC 42 ms
29,192 KB
testcase_19 AC 85 ms
57,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

constexpr ll mod=1e9+7;

void add(int &x,int y){
    x+=y;
    if(x>=mod)x-=mod;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<vector<int>> dp(n,vector<int>(3));
    dp[0][1]=1;
    for(int i=0;i+1<n;i++){
        add(dp[i+1][0],dp[i][1]);
        add(dp[i+1][0],dp[i][2]);
        add(dp[i+1][1],dp[i][0]);
        add(dp[i+1][2],dp[i][1]);
    }
    int res=0;
    for(int i=0;i<3;i++){
        add(res,dp[n-1][i]);
    }
    cout << res << endl;
}
0