結果

問題 No.314 ケンケンパ
ユーザー wunderkammer2wunderkammer2
提出日時 2020-01-10 12:55:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 1,000 ms
コード長 1,451 bytes
コンパイル時間 916 ms
コンパイル使用メモリ 99,816 KB
実行使用メモリ 57,728 KB
最終ジャッジ日時 2023-08-15 14:24:24
合計ジャッジ時間 1,980 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
56,880 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 6 ms
8,608 KB
testcase_18 AC 20 ms
29,096 KB
testcase_19 AC 33 ms
57,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

int main()
{	
	int N;
	cin >> N;

	//ケン:0、パ:1とすると2歩分のパターンは
	//00→可
	//01→可
	//10→可
	//11→不可

	//よって、ケンケンパのコースの末尾が00、01、10のパターンを使用して
	//動的計画法で計算すればよい

	if (N == 1)
	{
		cout << 1 << endl;
		return 0;
	}

	//dp[i][j][k] := 長さがkで末尾がijのケンケンパのコースの個数を10^9+7で割った数
	vector<vector<vector<ll>>> dp(2, vector<vector<ll>>(2, vector<ll>(N + 1, 0)));
	//auto dp = new vector<vector<vector<ll>>>(2, vector<vector<ll>>(2, vector<ll>(N, 0)));
	
	//初期化
	dp[0][0][2] = 1;
	dp[0][1][2] = 1;
	dp[1][0][2] = 0;
	//dp[1][1][2] = 1;

	reple(i, 3, N)
	{
		//ケンは2回まで
		dp[0][0][i] = dp[1][0][i - 1] % mod;
		dp[0][1][i] = (dp[0][0][i - 1] + dp[1][0][i - 1]) % mod;
		dp[1][0][i] = dp[0][1][i - 1] % mod;
	}

	cout << (dp[0][0][N] + dp[0][1][N] + dp[1][0][N]) % mod << endl;

	return 0;
}
0