結果

問題 No.93 ペガサス
ユーザー kyuridenamidakyuridenamida
提出日時 2016-02-20 01:29:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 86 ms / 5,000 ms
コード長 1,053 bytes
コンパイル時間 1,618 ms
コンパイル使用メモリ 159,684 KB
実行使用メモリ 19,680 KB
最終ジャッジ日時 2023-10-23 18:36:58
合計ジャッジ時間 2,516 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
19,576 KB
testcase_01 AC 6 ms
19,576 KB
testcase_02 AC 7 ms
19,576 KB
testcase_03 AC 7 ms
19,576 KB
testcase_04 AC 18 ms
19,612 KB
testcase_05 AC 10 ms
19,596 KB
testcase_06 AC 9 ms
19,592 KB
testcase_07 AC 50 ms
19,652 KB
testcase_08 AC 26 ms
19,628 KB
testcase_09 AC 84 ms
19,680 KB
testcase_10 AC 7 ms
19,580 KB
testcase_11 AC 8 ms
19,588 KB
testcase_12 AC 72 ms
19,668 KB
testcase_13 AC 25 ms
19,624 KB
testcase_14 AC 12 ms
19,600 KB
testcase_15 AC 63 ms
19,664 KB
testcase_16 AC 15 ms
19,608 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 6 ms
19,576 KB
testcase_19 AC 86 ms
19,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0 ; (i) < (int)(n) ; (i)++)
#define REP(i,a,b) for(int (i) = a ; (int)(i) <= (int)(b) ; (i)++)
#define all(n) (n).begin(),(n).end()
typedef long long ll;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<long long,long long> Pii;
typedef vector<Pii> VPii;
int mod = 1000000007;
int N;
int dp[1010][1010][2][2];

long long f(int n,int adj,int n2n4,int n1n3){
	if( adj < 0 ) return 0;

	int &dv = dp[n][adj][n2n4][n1n3];
	if( n == N ) return adj == 0 && n2n4 == 0 && n1n3 == 0;
	if( dv != -1 ) return dv;
	int d_n2 = 2 - n2n4;
	long long ans = 0;
	if( n2n4 ) ans += f(n+1,adj     ,n1n3,1);
	if( n1n3 ) ans += f(n+1,adj+n2n4,0,0);
	ans += d_n2 * f(n+1,adj+n2n4,n1n3,1);
	int nopro = n + 1 - adj - n2n4 - n1n3 - d_n2;
	ans += nopro * f(n+1,adj+n2n4,n1n3,0);
	ans += adj * f(n+1,adj-1+n2n4,n1n3,0);


	return dv = ans % mod;
}   
int main(){
	cin >> N;
	if( N == 1 ){
		cout << 1 << endl;
	}else{
		memset(dp,-1,sizeof(dp));
		cout << (f(2,0,0,0) * 2) %mod << endl;
	}
}
0