結果

問題 No.314 ケンケンパ
コンテスト
ユーザー kongarishisyamo
提出日時 2016-04-17 00:39:35
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 6 ms / 1,000 ms
コード長 388 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 495 ms
コンパイル使用メモリ 71,124 KB
実行使用メモリ 7,680 KB
最終ジャッジ日時 2026-04-20 06:52:08
合計ジャッジ時間 1,508 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<string>

using namespace std;

#define NMAX 1000000
#define MOD 1000000007
int main(){

	int N;
	int dp[NMAX+1]={0};

	dp[0]=1;

	cin>>N;

	for(int i=0;i<=N;i++){
		for(int j=2;j<=3&&i+j<=N;j++){
			dp[i+j]+=dp[i];
			dp[i+j]%=MOD;
		}
	}

	int ans=0;
	if(N>=1) ans+=dp[N-1],ans%=MOD;
	if(N>=2) ans+=dp[N-2],ans%=MOD;
	ans+=dp[N],ans%=MOD;

	cout<<ans<<endl;
}
0