結果

問題 No.2137 Stairs of Permutation
ユーザー ぷらぷら
提出日時 2022-11-25 22:49:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 519 ms / 2,000 ms
コード長 1,587 bytes
コンパイル時間 2,122 ms
コンパイル使用メモリ 197,772 KB
実行使用メモリ 316,108 KB
最終ジャッジ日時 2024-04-10 03:57:41
合計ジャッジ時間 8,988 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 88 ms
55,372 KB
testcase_03 AC 364 ms
223,816 KB
testcase_04 AC 308 ms
185,412 KB
testcase_05 AC 239 ms
144,068 KB
testcase_06 AC 493 ms
294,980 KB
testcase_07 AC 519 ms
310,724 KB
testcase_08 AC 56 ms
36,548 KB
testcase_09 AC 27 ms
19,660 KB
testcase_10 AC 80 ms
48,840 KB
testcase_11 AC 469 ms
282,056 KB
testcase_12 AC 181 ms
109,128 KB
testcase_13 AC 253 ms
153,160 KB
testcase_14 AC 374 ms
225,608 KB
testcase_15 AC 514 ms
310,980 KB
testcase_16 AC 172 ms
104,396 KB
testcase_17 AC 151 ms
92,104 KB
testcase_18 AC 234 ms
141,388 KB
testcase_19 AC 191 ms
117,192 KB
testcase_20 AC 130 ms
78,920 KB
testcase_21 AC 501 ms
305,996 KB
testcase_22 AC 3 ms
6,940 KB
testcase_23 AC 517 ms
316,108 KB
testcase_24 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int mod = 998244353;

long long fac[200005], finv[200005], inv[200005];

void COMinit() {
    fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
    for (int i = 2; i < 200005; i++) {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

long long choose(int n,int k) {
    if(n < 0 || k < 0) return 0;
    if(n == 0) return 1;
    return COM(n+k-1,k-1);
}

long long modpow(long long a,long long b) {
    long long ans = 1;
    while(b) {
        if(b & 1) {
            (ans *= a) %= mod;
        }
        (a *= a) %= mod;
        b /= 2;
    }
    return ans;
}

void mpl(int &x,int y) {
    x += y;
    if(x >= mod) x -= mod;
}

int dp[10001000][4];
int dp2[10001000][4];

int main() {
    int N;
    cin >> N;
    int ans = 0;
    dp[0][0] = 1;
    dp2[0][0] = 1;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= 3; j++) {
            mpl(dp[i+1][j],1ll*dp[i][j]*i%mod);
            for(int k = j; k <= j+1; k++) {
                if(k == 4) continue;
                mpl(dp[i+1][k],dp[i][j]);
            }
            mpl(dp2[i+1][j],1ll*dp2[i][j]*i%mod);
            if(j != 3) {
                mpl(dp2[i+1][j+1],dp2[i][j]);
            }
        }
    }
    mpl(ans,6ll*dp[N][3]%mod);
    mpl(ans,6ll*dp[N][2]%mod);
    mpl(ans,dp[N][1]);
    cout << ans << endl;
}
0