結果

問題 No.93 ペガサス
ユーザー nxterunxteru
提出日時 2018-06-24 13:20:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 5,000 ms
コード長 1,247 bytes
コンパイル時間 560 ms
コンパイル使用メモリ 69,420 KB
実行使用メモリ 22,720 KB
最終ジャッジ日時 2023-09-13 13:36:49
合計ジャッジ時間 1,928 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 9 ms
7,344 KB
testcase_05 AC 4 ms
5,144 KB
testcase_06 AC 4 ms
4,620 KB
testcase_07 AC 24 ms
14,920 KB
testcase_08 AC 13 ms
9,324 KB
testcase_09 AC 40 ms
22,356 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 34 ms
19,596 KB
testcase_13 AC 12 ms
8,700 KB
testcase_14 AC 6 ms
5,732 KB
testcase_15 AC 30 ms
18,192 KB
testcase_16 AC 7 ms
6,404 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 41 ms
22,720 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