結果

問題 No.314 ケンケンパ
ユーザー kazuma
提出日時 2017-07-26 13:45:02
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 80 ms / 1,000 ms
コード長 504 bytes
コンパイル時間 2,047 ms
コンパイル使用メモリ 197,928 KB
最終ジャッジ日時 2025-01-05 01:52:54
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

int main()
{
	int N;
	cin >> N;
	if (N == 1) {
		cout << 1 << endl;
		return 0;
	}
	vector<vector<ll>> dp(N + 1, vector<ll>(3));
	dp[2][0] = 1; dp[2][1] = 1;
	for (int i = 3; i <= N; i++) {
		dp[i][0] = dp[i - 1][2];
		dp[i][1] = (dp[i - 1][2] + dp[i - 1][0]) % mod;
		dp[i][2] = dp[i - 1][1];
	}
	ll res = 0;
	for (int i = 0; i < 3; i++) {
		res = (res + dp[N][i]) % mod;
	}
	cout << res << endl;
	return 0;
}
0