結果

問題 No.314 ケンケンパ
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-08-30 00:12:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 27 ms / 1,000 ms
コード長 819 bytes
コンパイル時間 485 ms
コンパイル使用メモリ 59,736 KB
実行使用メモリ 27,008 KB
最終ジャッジ日時 2024-04-26 17:22:04
合計ジャッジ時間 1,232 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
26,752 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 5 ms
5,888 KB
testcase_18 AC 14 ms
14,848 KB
testcase_19 AC 27 ms
27,008 KB
権限があれば一括ダウンロードができます

ソースコード

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番目まで考えて、j回連続ケン
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