結果

問題 No.314 ケンケンパ
ユーザー imulanimulan
提出日時 2016-02-08 21:48:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 54 ms / 1,000 ms
コード長 904 bytes
コンパイル時間 1,686 ms
コンパイル使用メモリ 160,012 KB
実行使用メモリ 68,748 KB
最終ジャッジ日時 2023-10-21 20:25:47
合計ジャッジ時間 2,431 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
68,044 KB
testcase_01 AC 8 ms
27,088 KB
testcase_02 AC 8 ms
27,088 KB
testcase_03 AC 8 ms
27,088 KB
testcase_04 AC 8 ms
27,088 KB
testcase_05 AC 8 ms
27,088 KB
testcase_06 AC 8 ms
27,088 KB
testcase_07 AC 8 ms
27,088 KB
testcase_08 AC 8 ms
27,088 KB
testcase_09 AC 8 ms
27,088 KB
testcase_10 AC 8 ms
27,096 KB
testcase_11 AC 7 ms
27,104 KB
testcase_12 AC 8 ms
27,112 KB
testcase_13 AC 7 ms
27,124 KB
testcase_14 AC 8 ms
27,324 KB
testcase_15 AC 8 ms
27,500 KB
testcase_16 AC 9 ms
28,136 KB
testcase_17 AC 12 ms
31,248 KB
testcase_18 AC 30 ms
47,016 KB
testcase_19 AC 54 ms
68,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long ll;
#define rep(i,n) for(i=0;i<n;++i)
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define mp make_pair
#define pb push_back
#define fi first
#define sc second

const long mod=1e9+7;
long n;

//今x歩まで進んできて、ケンがy回連続している
long dp[1000001][3];
long rec(long x, long y){
  if(dp[x][y]>=0) return dp[x][y];

  long ret=0;
  if(x==n) ret=1;
  else{
    if(y==0){//ケンしか置けない
      ret=rec(x+1,y+1);
    }
    else if(y==1){//両方おける
      long a=rec(x+1,y+1)%mod;
      long b=rec(x+1,0)%mod;
      ret=a+b;
    }
    else if(y==2){//パしか置けない
      ret=rec(x+1,0);
    }
  }

  return dp[x][y]=ret%mod;
}

int main(int argc, char const *argv[]) {
  cin >>n;
  memset(dp,-1,sizeof(dp));
  std::cout << rec(0,0) << std::endl;
  return 0;
}
0