結果

問題 No.314 ケンケンパ
ユーザー naimonon77naimonon77
提出日時 2015-12-12 17:42:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 1,000 ms
コード長 958 bytes
コンパイル時間 1,117 ms
コンパイル使用メモリ 66,592 KB
実行使用メモリ 11,272 KB
最終ジャッジ日時 2023-10-13 11:50:28
合計ジャッジ時間 2,441 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
11,272 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 1 ms
4,368 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 1 ms
4,368 KB
testcase_09 AC 2 ms
4,368 KB
testcase_10 AC 2 ms
4,368 KB
testcase_11 AC 2 ms
4,368 KB
testcase_12 AC 1 ms
4,368 KB
testcase_13 AC 2 ms
4,368 KB
testcase_14 AC 1 ms
4,368 KB
testcase_15 AC 2 ms
4,372 KB
testcase_16 AC 2 ms
4,368 KB
testcase_17 AC 3 ms
4,368 KB
testcase_18 AC 5 ms
7,612 KB
testcase_19 AC 8 ms
11,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>
#include <algorithm>
#include <limits.h>
#include <cmath>
#include <time.h>
#include <functional>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define MOD1 1000000007;
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/*  */
ull dp[1000005];
// dp[i]はiがパーで終わる奴
void solve(int n)
{
  int i;
  dp[0] = 1; //便宜上
  dp[1] = 0;
  dp[2] = 1;
  dp[3] = 1;
  dp[4] = 1;
  for(i=5;i<n+1;i++) {
    dp[i] = (dp[i-2] + dp[i-3])%MOD1 ;
  }
}
int main(void)
{
  int test = 0;
  int i,j,k,l;
  int N;
  ull rep;
  cin >> N;
  solve(N);
  if(test) {
    for(i=0;i<N+1;i++) {
      printf("dp[%d] = %llu\n",i,dp[i]);
    }
  }
  if(N > 2) {
    rep = (dp[N] + dp[N-1] + dp[N-2]) %MOD1;
  }
  else {
    switch(N) {
    case 2: rep = 2;break;
    case 1: rep = 1;break;
    }
  }
  cout << rep << endl;
  return 0;
}
0