結果

問題 No.336 門松列列
ユーザー chocoruskchocorusk
提出日時 2019-01-13 08:52:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 946 bytes
コンパイル時間 973 ms
コンパイル使用メモリ 92,012 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 18:45:36
合計ジャッジ時間 1,782 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 16 ms
4,368 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 3 ms
4,368 KB
testcase_07 AC 6 ms
4,368 KB
testcase_08 AC 10 ms
4,372 KB
testcase_09 AC 15 ms
4,368 KB
testcase_10 AC 16 ms
4,368 KB
testcase_11 AC 16 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int MOD=1e9+7;
int main()
{
	int n; cin>>n;
	if(n<=2){
		cout<<0<<endl;
		return 0;
	}
	int dp[2][2017];
	int s[2][2017];
	s[0][0]=0, s[0][1]=1;
	s[1][0]=s[1][1]=1;
	for(int i=3; i<=n; i++){
		for(int j=0; j<i; j++){
			if(j) dp[1][j]=(s[0][i-2]-s[0][j-1]+MOD)%MOD;
			else dp[1][j]=s[0][i-2];
		}
		for(int j=1; j<i; j++){
			dp[0][j]=s[1][j-1];
		}
		s[0][0]=dp[0][0], s[1][0]=dp[1][0];
		for(int j=1; j<i; j++){
			s[0][j]=(s[0][j-1]+dp[0][j])%MOD;
			s[1][j]=(s[1][j-1]+dp[1][j])%MOD;
		}
	}
	cout<<(s[0][n-1]+s[1][n-1])%MOD<<endl;
	return 0;
}
0