結果

問題 No.314 ケンケンパ
ユーザー RyuRyu
提出日時 2018-01-17 15:29:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 1,000 ms
コード長 1,002 bytes
コンパイル時間 683 ms
コンパイル使用メモリ 80,640 KB
実行使用メモリ 26,784 KB
最終ジャッジ日時 2023-08-25 20:34:00
合計ジャッジ時間 2,080 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
26,436 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 5 ms
5,668 KB
testcase_18 AC 18 ms
14,568 KB
testcase_19 AC 35 ms
26,784 KB
権限があれば一括ダウンロードができます

ソースコード

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