結果

問題 No.93 ペガサス
ユーザー dkknk
提出日時 2024-08-18 00:55:22
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 16 ms / 5,000 ms
コード長 2,794 bytes
コンパイル時間 3,999 ms
コンパイル使用メモリ 265,824 KB
実行使用メモリ 22,432 KB
最終ジャッジ日時 2024-08-18 00:55:33
合計ジャッジ時間 4,993 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,j,n) for(ll i=j;i<(ll)(n);i++)
#define rrep(i,j,n) for(ll i=j;i>=n;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define pb push_back
#define mp make_pair
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define UNIQUE(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end())
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
template<class T> bool chmax(T &a, const T &b){if(a<b) {a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b){if(a>b) {a=b;return 1;}return 0;}
const ll LINF = 1LL << 60LL;
const int IINF = (1 << 30) - 1;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
using mint = modint1000000007;
mint dp[1100][1100][2][2] = {0};
void solve(){
ll n; cin >> n;
dp[1][0][0][0] = 1;
dp[2][0][0][0] = 2;
rep(i,2,n){
rep(j,0,i){
if(j == 0){
// i+1 i-1 or i-1 i+1
dp[i+1][j+1][0][1] += 2*dp[i][j][0][0];
// others
dp[i+1][j][0][0] += (i-1)*dp[i][j][0][0];
}
else{
// i+1 i-1 or i-1 i+1
dp[i+1][j+1][0][1] += 2*dp[i][j][0][0];
// x i+1 x+2
dp[i+1][j-1][0][0] += j*dp[i][j][0][0];
// others
dp[i+1][j][0][0] += (i-j-1)*dp[i][j][0][0];
// i-2 i+1 i
dp[i+1][j-1][0][0] += dp[i][j][0][1];
// i+1 i-1 or i-1 i+1
dp[i+1][j+1][1][1] += 2*dp[i][j][0][1];
// x i+1 x+2
dp[i+1][j-1][1][0] += (j-1)*dp[i][j][0][1];
//others
dp[i+1][j][1][0] += (i-j-1)*dp[i][j][0][1];
// i+1 i-1 or i-1 i+1
dp[i+1][j+1][1][1] += dp[i][j][1][1];
// i-2 i+1 i
dp[i+1][j-1][0][0] += dp[i][j][1][1];
// x i+1 x+2
dp[i+1][j-1][1][0] += (j-2)*dp[i][j][1][1];
// x-3 i+1 x-1
dp[i+1][j][1][1] += dp[i][j][1][1];
// others
dp[i+1][j][1][0] += (i-j)*dp[i][j][1][1];
dp[i+1][j+1][0][1] += dp[i][j][1][0];
dp[i+1][j-1][0][0] += (j-1)*dp[i][j][1][0];
// others
dp[i+1][j][0][1] += dp[i][j][1][0];
dp[i+1][j][0][0] += (i-j)*dp[i][j][1][0];
}
}
}
cout << dp[n][0][0][0].val() << endl;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
ll T;
T = 1;
/*
cin >> T;
*/
while(T--) solve();
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0