結果

問題 No.314 ケンケンパ
ユーザー srup٩(๑`н´๑)۶
提出日時 2016-08-29 20:59:12
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 19 ms / 1,000 ms
コード長 802 bytes
コンパイル時間 452 ms
コンパイル使用メモリ 60,684 KB
実行使用メモリ 26,960 KB
最終ジャッジ日時 2024-11-14 06:48:35
合計ジャッジ時間 1,194 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
const int mod = 1e9 + 7;
//dp[i][j] := i番目まで考えて、
ll dp[1000010][3];
int main(void){
	int n; cin >> n;
	rep(i, n)rep(j, 3)dp[i][j] = 0;
	dp[1][1] = 1;//ケン
	for (int i = 1; i < n; ++i){
		for (int j = 0; j < 3; ++j){
			if(j == 0){//*パー
				(dp[i + 1][1] += dp[i][0]) %= mod;//ケン
			}else if(j == 1){//*パー ケン
				(dp[i + 1][0] += dp[i][1]) %= mod;//パー
				(dp[i + 1][2] += dp[i][1]) %= mod;//ケン
			}else if(j == 2){//*パー ケン ケン
				(dp[i + 1][0] += dp[i][2]) %= mod;//パー
			}
		}
	}

	ll ans = 0;
	rep(i, 3){
		(ans += dp[n][i]) % mod;
	}
	printf("%lld\n", ans % mod);
	return 0;
}
0