結果
問題 |
No.93 ペガサス
|
ユーザー |
![]() |
提出日時 | 2021-10-27 20:17:13 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 200 ms / 5,000 ms |
コード長 | 1,405 bytes |
コンパイル時間 | 4,924 ms |
コンパイル使用メモリ | 257,676 KB |
最終ジャッジ日時 | 2025-01-25 07:48:14 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
ソースコード
#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; }