結果

問題 No.314 ケンケンパ
ユーザー hkrhkr
提出日時 2017-02-16 12:54:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 25 ms / 1,000 ms
コード長 602 bytes
コンパイル時間 487 ms
コンパイル使用メモリ 62,616 KB
実行使用メモリ 34,396 KB
最終ジャッジ日時 2023-08-28 17:37:23
合計ジャッジ時間 1,896 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
34,364 KB
testcase_01 AC 14 ms
34,308 KB
testcase_02 AC 15 ms
34,280 KB
testcase_03 AC 13 ms
34,396 KB
testcase_04 AC 14 ms
34,048 KB
testcase_05 AC 15 ms
34,288 KB
testcase_06 AC 15 ms
34,128 KB
testcase_07 AC 15 ms
34,076 KB
testcase_08 AC 14 ms
34,016 KB
testcase_09 AC 14 ms
34,124 KB
testcase_10 AC 14 ms
34,144 KB
testcase_11 AC 16 ms
34,236 KB
testcase_12 AC 15 ms
34,364 KB
testcase_13 AC 15 ms
34,120 KB
testcase_14 AC 15 ms
34,208 KB
testcase_15 AC 16 ms
34,080 KB
testcase_16 AC 15 ms
34,164 KB
testcase_17 AC 15 ms
34,188 KB
testcase_18 AC 19 ms
34,188 KB
testcase_19 AC 24 ms
34,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector< vector<long long> > dp;
    dp = vector< vector<long long> >(3, vector<long long>(1000000));
    dp[0][0] = 0;
    dp[1][0] = 1;
    dp[2][0] = 0;
    long long mod= 1e9 + 7;
    for(int i=1;i<n;i++) {
        dp[0][i] = dp[2][i-1] + dp[1][i-1];
        dp[1][i] = dp[0][i-1];
        dp[2][i] = dp[1][i-1];

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

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