結果

問題 No.314 ケンケンパ
ユーザー Ryu
提出日時 2018-01-17 15:29:56
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 37 ms / 1,000 ms
コード長 1,002 bytes
コンパイル時間 744 ms
コンパイル使用メモリ 82,696 KB
実行使用メモリ 26,880 KB
最終ジャッジ日時 2024-12-24 06:42:42
合計ジャッジ時間 1,792 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <numeric>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <stack>

const int MOD = 1e9 + 7;
const int iINF = 100000000;
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct
{
    int to;
    int cost;
};

ll N, dp[1000010][3];

int main()
{
    cin >> N;

    dp[1][1] = 1;
    for (int i = 1; i < N; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            if (j == 0)
                (dp[i + 1][1] += dp[i][0]) %= MOD;
            else if (j == 1)
            {
                (dp[i + 1][2] += dp[i][1]) %= MOD;
                (dp[i + 1][0] += dp[i][1]) %= MOD;
            }
            else
                (dp[i + 1][0] += dp[i][2]) %= MOD;
        }
    }

    ll ans = 0;
    rep(i, 3)
        (ans += dp[N][i]) %= MOD;

    cout << ans << endl;

    return 0;
}
0