結果

問題 No.314 ケンケンパ
ユーザー turukameturukame
提出日時 2017-01-31 14:56:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 1,000 ms
コード長 526 bytes
コンパイル時間 3,180 ms
コンパイル使用メモリ 164,212 KB
実行使用メモリ 46,308 KB
最終ジャッジ日時 2023-08-25 14:15:21
合計ジャッジ時間 3,075 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
45,772 KB
testcase_01 AC 6 ms
15,056 KB
testcase_02 AC 6 ms
15,376 KB
testcase_03 AC 7 ms
15,124 KB
testcase_04 AC 6 ms
15,128 KB
testcase_05 AC 6 ms
15,108 KB
testcase_06 AC 7 ms
15,112 KB
testcase_07 AC 6 ms
15,060 KB
testcase_08 AC 6 ms
15,068 KB
testcase_09 AC 7 ms
15,176 KB
testcase_10 AC 6 ms
15,184 KB
testcase_11 AC 6 ms
15,264 KB
testcase_12 AC 7 ms
15,076 KB
testcase_13 AC 6 ms
15,076 KB
testcase_14 AC 7 ms
15,240 KB
testcase_15 AC 7 ms
15,440 KB
testcase_16 AC 8 ms
15,960 KB
testcase_17 AC 11 ms
18,184 KB
testcase_18 AC 27 ms
30,016 KB
testcase_19 AC 48 ms
46,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int N;
const int MAX_N = 1000010;
int dp[MAX_N][3];
const int MOD = 1000000007;

int memo(int pos, int k) {
  if (k >= 3) {
    return 0;
  }
  if (pos >= N) {
    return 1;
  }
  int &res = dp[pos][k];
  if (res >= 0) {
    return res;
  }
  res = 0;
  // ken
  res += memo(pos + 1, k + 1);
  res %= MOD;
  if (k > 0) { // pa
    res += memo(pos + 1, 0);
    res %= MOD;
  }
  return res;
}

int main() {
  cin >> N;
  memset(dp, -1, sizeof(dp));
  cout << memo(0, 0) << endl;
}
0