結果

問題 No.314 ケンケンパ
ユーザー dearorange31
提出日時 2017-10-02 01:05:08
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 19 ms / 1,000 ms
コード長 668 bytes
コンパイル時間 827 ms
コンパイル使用メモリ 57,588 KB
実行使用メモリ 15,232 KB
最終ジャッジ日時 2024-11-15 21:52:32
合計ジャッジ時間 1,515 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<string.h>

using namespace std;

const int lim = 1e6 + 1;
int dp[lim][3];
int main(){
	memset(dp,0,sizeof(dp));
	int n;
	cin >> n;
	dp[0][1] = 1;
	int div = 1e9 + 7;
	for(int i = 0;i < n-1;i++){
		for(int j = 0;j < 3;j++){
			if(dp[i][j] > 0){
				if(j == 0){
					dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % div;
				}else if(j == 2){
					dp[i+1][0] = (dp[i+1][0] + dp[i][j]) % div;
				}else{
					dp[i+1][0] = (dp[i+1][0] + dp[i][j]) % div;
					dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % div;
				}
			}
		}
	}
	
	int ans = 0;
	for(int i = 0;i < 3;i++){
		ans = (ans + dp[n-1][i]) % div;
	}
	
	cout << ans << endl;
}
0