結果

問題 No.93 ペガサス
ユーザー msm1993msm1993
提出日時 2020-11-05 09:43:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 5,000 ms
コード長 1,247 bytes
コンパイル時間 585 ms
コンパイル使用メモリ 68,800 KB
実行使用メモリ 22,696 KB
最終ジャッジ日時 2023-09-29 16:45:32
合計ジャッジ時間 1,832 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 8 ms
7,304 KB
testcase_05 AC 3 ms
5,144 KB
testcase_06 AC 3 ms
4,576 KB
testcase_07 AC 21 ms
14,812 KB
testcase_08 AC 11 ms
9,392 KB
testcase_09 AC 39 ms
22,316 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,384 KB
testcase_12 AC 32 ms
19,716 KB
testcase_13 AC 10 ms
8,672 KB
testcase_14 AC 5 ms
5,688 KB
testcase_15 AC 27 ms
17,868 KB
testcase_16 AC 7 ms
6,572 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 39 ms
22,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;
#define M 1000000007
typedef long long ll;
void add(ll &a,ll b){a=(a+b%M)%M;}
int n;
ll dp[1005][1005][2][2];
int main(void){
    cin>>n;
    if(n<=2){
        cout<<n<<endl;
        return 0;
    }
    dp[2][0][0][0]=2;
    for(ll i=2;i<n;i++){
        for(ll j=0;j<i;j++){
            ll x=dp[i][j][0][0];
            if(j>0)add(dp[i+1][j-1][0][0],x*j);
            add(dp[i+1][j+1][0][1],x*2);
            if(i-j-1>0)add(dp[i+1][j][0][0],x*(i-j-1));
            x=dp[i][j][0][1];
            if(j-1>0)add(dp[i+1][j-1][1][0],x*(j-1));
            add(dp[i+1][j-1][0][0],x);
            add(dp[i+1][j+1][1][1],x*2);
            if(i-j-1>0)add(dp[i+1][j][1][0],x*(i-j-1));
            x=dp[i][j][1][0];
            if(j-1>0)add(dp[i+1][j-1][0][0],x*(j-1));
            add(dp[i+1][j][0][1],x);
            add(dp[i+1][j+1][0][1],x);
            if(i-j>0)add(dp[i+1][j][0][0],x*(i-j));
            x=dp[i][j][1][1];
            if(j-2>0)add(dp[i+1][j-1][1][0],x*(j-2));
            add(dp[i+1][j-1][0][0],x);
            add(dp[i+1][j][1][1],x);
            add(dp[i+1][j+1][1][1],x);
            if(i-j>0)add(dp[i+1][j][1][0],x*(i-j));
        }
    }
    cout<<dp[n][0][0][0]<<endl;
}
0