結果

問題 No.314 ケンケンパ
ユーザー aa
提出日時 2016-07-09 05:40:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 1,000 ms
コード長 617 bytes
コンパイル時間 341 ms
コンパイル使用メモリ 33,788 KB
実行使用メモリ 118,408 KB
最終ジャッジ日時 2024-04-21 09:18:07
合計ジャッジ時間 1,697 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
117,204 KB
testcase_01 AC 16 ms
55,944 KB
testcase_02 AC 16 ms
55,736 KB
testcase_03 AC 16 ms
55,680 KB
testcase_04 AC 16 ms
55,620 KB
testcase_05 AC 16 ms
55,820 KB
testcase_06 AC 16 ms
55,676 KB
testcase_07 AC 15 ms
55,728 KB
testcase_08 AC 19 ms
55,860 KB
testcase_09 AC 15 ms
55,656 KB
testcase_10 AC 16 ms
55,888 KB
testcase_11 AC 16 ms
55,944 KB
testcase_12 AC 16 ms
55,812 KB
testcase_13 AC 16 ms
55,860 KB
testcase_14 AC 15 ms
56,240 KB
testcase_15 AC 16 ms
56,304 KB
testcase_16 AC 17 ms
57,436 KB
testcase_17 AC 22 ms
61,920 KB
testcase_18 AC 47 ms
85,552 KB
testcase_19 AC 82 ms
118,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>

using namespace std;

const int mod = 1e9+7;
int n;
long long dp[1111111][2][3];

long long solve(int a, int b, int c) {
  if (dp[a][b][c] >= 0) return dp[a][b][c];
  if (a == n) return 1;
  long long res = 0;
  if (b == 0) {
    if (c < 2) {
      res = (res+solve(a+1, 0, c+1))%mod;
    }
    if (c > 0) {
      res = (res+solve(a+1, 1, 0))%mod;
    }
  } else {
    res = (res+solve(a+1, 0, c+1))%mod;
  }
  return dp[a][b][c] = res;
}

int main(void) {
  scanf("%d", &n);
  memset(dp, -1, sizeof(dp));
  long long res = solve(0, 0, 0);
  printf("%lld\n", res);
  return 0;
}
0