結果

問題 No.314 ケンケンパ
ユーザー fushime2fushime2
提出日時 2017-12-29 19:49:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 71 ms / 1,000 ms
コード長 656 bytes
コンパイル時間 1,154 ms
コンパイル使用メモリ 144,388 KB
実行使用メモリ 81,440 KB
最終ジャッジ日時 2023-08-23 09:02:10
合計ジャッジ時間 2,686 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
81,108 KB
testcase_01 AC 16 ms
50,196 KB
testcase_02 AC 16 ms
50,224 KB
testcase_03 AC 16 ms
50,212 KB
testcase_04 AC 15 ms
50,244 KB
testcase_05 AC 16 ms
50,196 KB
testcase_06 AC 16 ms
50,212 KB
testcase_07 AC 16 ms
50,208 KB
testcase_08 AC 15 ms
50,228 KB
testcase_09 AC 15 ms
50,320 KB
testcase_10 AC 16 ms
50,260 KB
testcase_11 AC 16 ms
50,368 KB
testcase_12 AC 15 ms
50,232 KB
testcase_13 AC 15 ms
50,240 KB
testcase_14 AC 16 ms
50,364 KB
testcase_15 AC 16 ms
50,504 KB
testcase_16 AC 17 ms
51,088 KB
testcase_17 AC 21 ms
53,348 KB
testcase_18 AC 42 ms
65,168 KB
testcase_19 AC 71 ms
81,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define mset(a,x) memset(a,x,sizeof(a))

const int mod = (int)1e9 + 7;
int N;

ll dp[1000005][3][2];
ll rec(int i, int ken, int pre) {
    ll &r = dp[i][ken][pre];
    if (r != -1) return r;
    if (ken > 2) return r = 0;
    if (i >= N) return r = 1;
    if (pre == 0)
        r = (rec(i + 1, ken + 1, 0) % mod + rec(i + 1, 0, 1) % mod) % mod;
    else
        r = rec(i + 1, ken + 1, 0) % mod;
    return r;
}

int main() {
    cin >> N;
    mset(dp, -1);
    cout << rec(0, 0, 1) << endl;
    return 0;
}
0