結果

問題 No.314 ケンケンパ
ユーザー トミートミー
提出日時 2024-03-30 01:11:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 1,000 ms
コード長 823 bytes
コンパイル時間 2,416 ms
コンパイル使用メモリ 205,620 KB
実行使用メモリ 58,020 KB
最終ジャッジ日時 2024-03-30 01:11:11
合計ジャッジ時間 3,378 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
57,096 KB
testcase_01 AC 3 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 3 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 3 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 3 ms
6,676 KB
testcase_15 AC 3 ms
6,676 KB
testcase_16 AC 5 ms
6,676 KB
testcase_17 AC 11 ms
8,832 KB
testcase_18 AC 40 ms
29,496 KB
testcase_19 AC 80 ms
58,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// コピーして使う!
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

int main() {
    ll n;
    cin >> n;
    if (n > 2) {
        // vector[n][i] iがケンケンパに対応(0,1,2)
        vector<vector<ll>> dp(n + 1, vector<ll>(3));
        ll ans = 0, mod = pow(10, 9) + 7;
        dp[1][0] = 1;
        dp[1][1] = 0;
        dp[1][2] = 0;
        dp[2][0] = 0;
        dp[2][1] = 1;
        dp[2][2] = 1;
        for (ll i = 3; i != dp.size(); i++) {
            dp[i][0] = dp[i - 1][2];
            dp[i][1] = dp[i - 1][0];
            dp[i][2] = (dp[i - 1][0] + dp[i - 1][1]) % mod;
        }
        for (ll i = 0; i != 3; i++) {
            ans = (ans + dp[dp.size() - 1][i]) % mod;
        }
        cout << ans << endl;
    } else {
        cout<<n<<endl;
    }

    system("pause");
}
0