結果

問題 No.93 ペガサス
ユーザー chocoruskchocorusk
提出日時 2020-03-26 22:35:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 5,000 ms
コード長 1,229 bytes
コンパイル時間 1,084 ms
コンパイル使用メモリ 110,160 KB
実行使用メモリ 31,024 KB
最終ジャッジ日時 2023-08-30 15:52:09
合計ジャッジ時間 2,846 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 14 ms
12,184 KB
testcase_05 AC 7 ms
7,884 KB
testcase_06 AC 6 ms
6,852 KB
testcase_07 AC 32 ms
22,876 KB
testcase_08 AC 19 ms
15,512 KB
testcase_09 AC 47 ms
30,720 KB
testcase_10 AC 3 ms
4,468 KB
testcase_11 AC 5 ms
5,836 KB
testcase_12 AC 41 ms
27,924 KB
testcase_13 AC 17 ms
14,360 KB
testcase_14 AC 10 ms
9,128 KB
testcase_15 AC 37 ms
26,300 KB
testcase_16 AC 11 ms
10,212 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 48 ms
31,024 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>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll dp[2][2][1010][1010];
int main()
{
	int n;
	cin>>n;
	if(n==1) cout<<1<<endl;
	else if(n==2) cout<<2<<endl;
	if(n<=2) return 0;
	dp[0][0][2][0]=2;
	for(int i=2; i<n; i++){
		for(int j=0; j<=i+1; j++){
			for(int p=0; p<2; p++){
				for(int q=0; q<2; q++){
					int c=j, d=i+1, e=2;
					if(p){
						(dp[q][1][i+1][j]+=dp[p][q][i][j])%=MOD;
						c--, d--, e--;
					}
					if(q){
						(dp[0][0][i+1][j-1]+=dp[p][q][i][j])%=MOD;
						c--, d--;
					}
					(dp[q][1][i+1][j+1]+=dp[p][q][i][j]*e)%=MOD;
					(dp[q][0][i+1][j-1]+=dp[p][q][i][j]*c)%=MOD;
					(dp[q][0][i+1][j]+=dp[p][q][i][j]*(d-c-e))%=MOD;
				}
			}
		}
	}
	cout<<dp[0][0][n][0]<<endl;
	return 0;
}
0