結果

問題 No.314 ケンケンパ
ユーザー shota525
提出日時 2018-05-07 01:29:55
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 108 ms / 1,000 ms
コード長 564 bytes
コンパイル時間 1,294 ms
コンパイル使用メモリ 157,664 KB
実行使用メモリ 93,312 KB
最終ジャッジ日時 2024-06-28 02:15:27
合計ジャッジ時間 2,462 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define DIV 1000000007

using namespace std;

int N;
int dp[3][2][1000001] = {{{0}}};

int rec(int ken = 0, int pa = 0, int count = 0){
    
    if(count == N) return 1;
    
    int &res = dp[ken][pa][count];
    if(res != 0) return res;
    
    if(ken < 2){
        res += rec(ken + 1, 0, count + 1);
        res %= DIV;
    }
    if(ken != 0 && pa == 0){
        res += rec(0 , 1, count + 1);
        res %= DIV;
    }
    
    return res;    
}

int main(void){
    
    cin >> N;
    
    cout << rec() << endl;
    
    return 0;
}
0