結果

問題 No.2137 Stairs of Permutation
ユーザー ぷらぷら
提出日時 2022-11-25 22:49:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 804 ms / 2,000 ms
コード長 1,587 bytes
コンパイル時間 2,165 ms
コンパイル使用メモリ 200,008 KB
実行使用メモリ 315,856 KB
最終ジャッジ日時 2023-07-25 10:59:07
合計ジャッジ時間 12,251 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,596 KB
testcase_01 AC 2 ms
5,388 KB
testcase_02 AC 136 ms
55,576 KB
testcase_03 AC 565 ms
222,984 KB
testcase_04 AC 469 ms
185,352 KB
testcase_05 AC 362 ms
143,288 KB
testcase_06 AC 747 ms
294,640 KB
testcase_07 AC 790 ms
310,592 KB
testcase_08 AC 88 ms
36,880 KB
testcase_09 AC 40 ms
18,820 KB
testcase_10 AC 117 ms
48,132 KB
testcase_11 AC 713 ms
281,428 KB
testcase_12 AC 273 ms
108,556 KB
testcase_13 AC 385 ms
152,788 KB
testcase_14 AC 574 ms
225,376 KB
testcase_15 AC 788 ms
310,876 KB
testcase_16 AC 264 ms
104,444 KB
testcase_17 AC 232 ms
92,148 KB
testcase_18 AC 358 ms
141,108 KB
testcase_19 AC 297 ms
117,300 KB
testcase_20 AC 197 ms
78,436 KB
testcase_21 AC 781 ms
306,316 KB
testcase_22 AC 2 ms
5,396 KB
testcase_23 AC 804 ms
315,856 KB
testcase_24 AC 2 ms
5,424 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