結果

問題 No.93 ペガサス
ユーザー maine_honzukimaine_honzuki
提出日時 2020-05-12 23:33:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 5,000 ms
コード長 1,487 bytes
コンパイル時間 2,157 ms
コンパイル使用メモリ 174,852 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-12 03:13:05
合計ジャッジ時間 3,355 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 11 ms
4,352 KB
testcase_05 AC 5 ms
4,352 KB
testcase_06 AC 4 ms
4,352 KB
testcase_07 AC 35 ms
4,352 KB
testcase_08 AC 17 ms
4,348 KB
testcase_09 AC 59 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 49 ms
4,348 KB
testcase_13 AC 15 ms
4,348 KB
testcase_14 AC 7 ms
4,352 KB
testcase_15 AC 44 ms
4,356 KB
testcase_16 AC 8 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 60 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

int main() {
    int N;
    cin >> N;

    vector<vector<ll>> dp(1, vector<ll>{1, 0});
    for (ll i = 1; i < N; i++) {
        ll n = dp.size();
        vector<vector<ll>> nxt(n + 1, vector<ll>(2, 0));
        if (i != N / 2) {
            for (ll a = 0; a <= n; a++) {
                if (a < n)
                    nxt[a][1] += dp[a][1];
                if (a > 0) {
                    nxt[a][1] += 2 * dp[a - 1][0];
                    nxt[a][1] += dp[a - 1][1];
                }
                nxt[a][1] %= mod;

                if (a + 1 < n) {
                    nxt[a][0] += (a + 1) * dp[a + 1][0];
                    nxt[a][0] += a * dp[a + 1][1];
                }
                if (a < n) {
                    nxt[a][0] += max(i - a - 1, 0ll) * dp[a][0];
                    nxt[a][0] += (i - a) * dp[a][1];
                }
                nxt[a][0] %= mod;
            }
        } else {
            for (ll a = 0; a <= n; a++) {
                if (a + 1 < n) {
                    nxt[a][0] += (a + 1) * dp[a + 1][0];
                    nxt[a][0] += (a + 1) * dp[a + 1][1];
                }
                if (a < n) {
                    nxt[a][0] += (i - a + 1) * dp[a][0];
                    nxt[a][0] += (i - a + 1) * dp[a][1];
                }

                nxt[a][0] %= mod;
            }
        }
        dp = nxt;
    }

    cout << dp[0][0] << endl;
}
0