結果

問題 No.314 ケンケンパ
ユーザー mmn15277198mmn15277198
提出日時 2021-02-01 11:31:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 1,000 ms
コード長 826 bytes
コンパイル時間 627 ms
コンパイル使用メモリ 73,552 KB
実行使用メモリ 57,844 KB
最終ジャッジ日時 2023-09-12 10:07:32
合計ジャッジ時間 1,909 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
56,676 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,388 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 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 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 4 ms
4,384 KB
testcase_17 AC 10 ms
8,512 KB
testcase_18 AC 41 ms
29,108 KB
testcase_19 AC 82 ms
57,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

int main(void){
    int n;
    cin >> n;
    vector<vector<ll>> dp(n + 10 , vector<ll>(2 , 0));
    dp[2][0] = 1;
    dp[3][1] = 1;
    for(int i = 2; i < n + 5; i++){
        dp[i + 2][0] += dp[i][0]; //  xo -> xo
        dp[i + 3][1] += dp[i][0]; // xo -> xxo
        dp[i + 3][1] += dp[i][1]; //  xxo -> xxo
        dp[i + 2][0] += dp[i][1]; // xxo -> xo
        dp[i + 2][0] %= mod; 
        dp[i + 3][1] %= mod;
    }
    
    // 丁度nで終わった回数と,n + 1で終わった回数
    cout << (dp[n][0] + dp[n][1] + dp[n + 1][0] + dp[n + 1][1]) % mod << endl;
    // n + 2 で終わった場合は、n - 1 -> xxo n - 1 -> xxo が同じなのでカウントしない

    return 0;
}
0