結果

問題 No.314 ケンケンパ
ユーザー zoom4638zoom4638
提出日時 2015-12-11 17:36:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 92 ms / 1,000 ms
コード長 799 bytes
コンパイル時間 396 ms
コンパイル使用メモリ 52,568 KB
実行使用メモリ 73,672 KB
最終ジャッジ日時 2023-10-13 10:57:31
合計ジャッジ時間 1,609 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
72,476 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 5 ms
5,212 KB
testcase_17 AC 11 ms
10,388 KB
testcase_18 AC 44 ms
37,060 KB
testcase_19 AC 92 ms
73,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

long long int dp[1000003][3][3];

int main() {
	int n;
	cin >> n;
	dp[1][1][0] = 1;
	
	for (int i = 2; i <= n; i++){
		for (int j = 0; j < 3; j++){
			for (int k = 0; k < 3; k++){
				if (dp[i - 1][j][k] != 0){
					if (j == 1 && k == 1){
						dp[i][2][j] += dp[i - 1][j][k];
						dp[i][2][j] %= 1000000007;
					}else{
						if (j == 2){
							dp[i][1][j] += dp[i - 1][j][k];
							dp[i][1][j] %= 1000000007;
						}else{
							for (int l = 1; l < 3; l++){
								dp[i][l][j] += dp[i - 1][j][k];
								dp[i][l][j] %= 1000000007;
							}
						}
					}
				}
			}
		}
	}
	
	long long int ans = 0;
	
	for (int i = 0; i < 3; i++){
		for (int j = 0; j < 3; j++){
			ans += dp[n][i][j];
			ans %= 1000000007;
		}
	}
	
	cout << ans << endl;
	return 0;
}
0