結果

問題 No.314 ケンケンパ
ユーザー hiragnhiragn
提出日時 2019-08-05 21:43:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 1,000 ms
コード長 704 bytes
コンパイル時間 1,438 ms
コンパイル使用メモリ 163,780 KB
実行使用メモリ 26,760 KB
最終ジャッジ日時 2023-09-25 17:28:46
合計ジャッジ時間 2,542 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const long long MOD = 1e9 + 7;

long long dp[1000001][3];

int main() {
    int n;
    cin >> n;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            dp[i][j] = 0;
        }
    }

    dp[1][1] = 1;// K
    for (int i = 1; i < n; ++i) {
        dp[i + 1][1] += dp[i][0];// P->K
        dp[i + 1][1] %= MOD;

        dp[i + 1][0] += dp[i][1] + dp[i][2];// K->P, KK->P
        dp[i + 1][0] %= MOD;
        
        dp[i + 1][2] += dp[i][1];// K->KK
        dp[i + 1][2] %= MOD;
    }

    long long ans = 0;
    for (int i = 0; i < 3; ++i) {
        ans = (ans + dp[n][i]) % MOD;
    }
    cout << ans << endl;
    return 0;
}
0