結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 5 ms
4,352 KB
testcase_19 AC 8 ms
4,352 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[2][3],pa[2];
const long long mod=1000000007; 

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

    return 0;
}
0