結果

問題 No.314 ケンケンパ
ユーザー Lay_ecLay_ec
提出日時 2015-12-07 20:41:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 41 ms / 1,000 ms
コード長 780 bytes
コンパイル時間 540 ms
コンパイル使用メモリ 74,388 KB
実行使用メモリ 34,584 KB
最終ジャッジ日時 2023-10-12 20:08:06
合計ジャッジ時間 1,512 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
34,192 KB
testcase_01 AC 2 ms
5,604 KB
testcase_02 AC 2 ms
5,512 KB
testcase_03 AC 2 ms
5,472 KB
testcase_04 AC 2 ms
5,336 KB
testcase_05 AC 2 ms
5,440 KB
testcase_06 AC 2 ms
5,396 KB
testcase_07 AC 2 ms
5,356 KB
testcase_08 AC 2 ms
5,592 KB
testcase_09 AC 2 ms
5,340 KB
testcase_10 AC 2 ms
5,336 KB
testcase_11 AC 2 ms
5,636 KB
testcase_12 AC 2 ms
5,392 KB
testcase_13 AC 2 ms
5,652 KB
testcase_14 AC 2 ms
5,428 KB
testcase_15 AC 2 ms
5,412 KB
testcase_16 AC 2 ms
5,808 KB
testcase_17 AC 6 ms
8,320 KB
testcase_18 AC 22 ms
19,908 KB
testcase_19 AC 41 ms
34,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
#include <stack>

using namespace std;

long long ken[1000010][3],pa[1000010];
const long long mod=1000000007; 

int main()
{
	int n;
	cin>>n;
	
	ken[1][1]=1;
	for(int i=1;i<n;i++){
		for(int j=1;j<3;j++){
			if(ken[i][j]==0) continue;
			//ケン->ケン
			if(j!=2) ken[i+1][j+1]=(ken[i+1][j+1]+ken[i][j])%mod;
			//ケン->パ
			pa[i+1]=(pa[i+1]+ken[i][j])%mod;
		}
		//パ->ケン
		if(pa[i]==0) continue;
		ken[i+1][1]=(ken[i+1][1]+pa[i]);
	}
	
	long long res=(ken[n][0]+ken[n][1]+ken[n][2]+pa[n])%mod;
	cout<<res<<endl;

    return 0;
}
0