結果

問題 No.93 ペガサス
コンテスト
ユーザー chocorusk
提出日時 2020-03-26 22:35:35
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 26 ms / 5,000 ms
コード長 1,229 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 786 ms
コンパイル使用メモリ 132,404 KB
実行使用メモリ 31,360 KB
最終ジャッジ日時 2026-06-05 23:21:27
合計ジャッジ時間 1,952 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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