結果

問題 No.93 ペガサス
ユーザー 沙耶花沙耶花
提出日時 2021-10-27 20:17:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 182 ms / 5,000 ms
コード長 1,405 bytes
コンパイル時間 4,992 ms
コンパイル使用メモリ 263,180 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 12:44:38
合計ジャッジ時間 6,447 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 30 ms
5,376 KB
testcase_05 AC 11 ms
5,376 KB
testcase_06 AC 8 ms
5,376 KB
testcase_07 AC 100 ms
5,376 KB
testcase_08 AC 48 ms
5,376 KB
testcase_09 AC 175 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 146 ms
5,376 KB
testcase_13 AC 42 ms
5,376 KB
testcase_14 AC 16 ms
5,376 KB
testcase_15 AC 130 ms
5,376 KB
testcase_16 AC 21 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 182 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000000000000


int main(){
	
	int N;
	cin>>N;
	
	if(N==1){
		cout<<1<<endl;
		return 0;
	}
	
	vector dp(N+3,vector(2,vector<mint>(2,0)));
	dp[0][0][0] = 2;
	for(int i=3;i<=N;i++){
		vector ndp(N+3,vector(2,vector<mint>(2,0)));
		rep(j,N+3){
			rep(k,2){
				rep(l,2){
					if(dp[j][k][l]==0)continue;
					if(k==0){
						if(l==0){
							ndp[j+1][0][1] += dp[j][k][l]*2;
							if(j!=0)ndp[j-1][0][0] += dp[j][k][l]*j;
							ndp[j][0][0] += dp[j][k][l] * (i-j-2);
						}
						else{
							ndp[j+1][1][1] += dp[j][k][l] * 2;
							ndp[j-1][0][0] += dp[j][k][l];
							ndp[j-1][1][0] += dp[j][k][l] * (j-1);
							ndp[j][1][0] += dp[j][k][l] * (i-j-2);
						}
					}
					else{
						if(l==0){
							ndp[j+1][0][1] += dp[j][k][l];
							ndp[j][0][1] += dp[j][k][l];
							if(j!=0)ndp[j-1][0][0] += dp[j][k][l]*(j-1);
							ndp[j][0][0] += dp[j][k][l] * (i-j-1);
						}
						else{
							ndp[j+1][1][1] += dp[j][k][l];
							ndp[j][1][1] += dp[j][k][l];
							ndp[j-1][0][0] += dp[j][k][l];
							ndp[j-1][1][0] += dp[j][k][l] * (j-2);
							ndp[j][1][0] += dp[j][k][l] * (i-j-1);
						}
					}
				}
			}
		}
		swap(dp,ndp);		
	}
	
	cout<<dp[0][0][0].val()<<endl;
	
	return 0;
}
0