結果

問題 No.2528 pop_(backfront or not)
ユーザー maeshunmaeshun
提出日時 2023-11-11 16:35:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 261 ms / 2,000 ms
コード長 3,372 bytes
コンパイル時間 4,874 ms
コンパイル使用メモリ 269,008 KB
実行使用メモリ 66,304 KB
最終ジャッジ日時 2023-11-11 16:35:29
合計ジャッジ時間 7,417 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 3 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 6 ms
6,676 KB
testcase_08 AC 9 ms
6,676 KB
testcase_09 AC 23 ms
8,320 KB
testcase_10 AC 65 ms
19,072 KB
testcase_11 AC 70 ms
20,224 KB
testcase_12 AC 100 ms
27,648 KB
testcase_13 AC 108 ms
30,208 KB
testcase_14 AC 133 ms
36,096 KB
testcase_15 AC 210 ms
54,400 KB
testcase_16 AC 261 ms
66,176 KB
testcase_17 AC 255 ms
66,304 KB
testcase_18 AC 252 ms
66,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for(int i=0;i<(n);++i)
#define rep1(i, n) for(int i=1;i<=(n);i++)
#define ll long long
using mint = modint998244353;
using P = pair<ll,ll>;
using lb = long double;
using T = tuple<ll, ll, ll>;
#ifdef LOCAL
#  include <debug_print.hpp>
#  define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define dbg(...) (static_cast<void>(0))
#endif

// combination mod prime
// https://youtu.be/8uowVvQ_-Mo?t=6002
// https://youtu.be/Tgd_zLfRZOQ?t=9928
struct modinv {
  int n; vector<mint> d;
  modinv(): n(2), d({0,1}) {}
  mint operator()(int i) {
    while (n <= i) d.push_back(-d[mint::mod()%n]*(mint::mod()/n)), ++n;
    return d[i];
  }
  mint operator[](int i) const { return d[i];}
} invs;
struct modfact {
  int n; vector<mint> d;
  modfact(): n(2), d({1,1}) {}
  mint operator()(int i) {
    while (n <= i) d.push_back(d.back()*n), ++n;
    return d[i];
  }
  mint operator[](int i) const { return d[i];}
} facts;
struct modfactinv {
  int n; vector<mint> d;
  modfactinv(): n(2), d({1,1}) {}
  mint operator()(int i) {
    while (n <= i) d.push_back(d.back()*invs(n)), ++n;
    return d[i];
  }
  mint operator[](int i) const { return d[i];}
} ifacts;
mint comb(int n, int k) {
  if (n < k || k < 0) return 0;
  return facts(n)*ifacts(k)*ifacts(n-k);
}

uint64_t combinations2(uint64_t n, uint64_t k) {
    uint64_t r = 1;
    for (uint64_t d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

// vector<vector<mint>> comb(n+1, vector<mint>(n+1));
// rep(i,n+1) comb[i][0] = 1;
// for(int i=1;i<=n;i++){
//     for(int j=1;j<=n;j++){
//         comb[i][j] = comb[i-1][j] + comb[i-1][j-1];
//     }
// }

//Lucasの定理(素数mod)
/* Com:nCk % p の計算のための構造体
    前処理・初期化: O(p^2)
    nCk(n,k): nCk % p の計算。O(log n)
*/
// struct Comb {
//     vector<vector<long long>> com;  // 前計算の結果を保存
//     long long p;                    // p は素数である必要がある
//     Comb(long long _p) : p(_p) {
//         init(p);
//     }
//     void init(long long p) {  // 動的計画法で前処理
//         com.assign(p, vector<long long>(p));
//         com[0][0] = 1;
//         for (int i = 1; i < p; i++) {
//             com[i][0] = 1;
//             for (int j = i; j > 0; j--) {
//                 com[i][j] = (com[i - 1][j - 1] + com[i - 1][j]) % p;
//             }
//         }
//     }
//     long long nCk(long long n, long long k) {
//         long long ret = 1;
//         while (n > 0) {  // 下から一桁ずつ計算する
//             int ni = n % p;
//             int ki = k % p;
//             ret *= com[ni][ki];
//             ret %= p;
//             n /= p;
//             k /= p;
//         }
//         return ret;
//     }
// };

int main()
{
    int n;
    cin >> n;
    vector<vector<mint>> dp(2*n+2, vector<mint>(2*n+2));
    dp[1][1] = 1;
    for(int i=1;i<=2*n-1;i+=2){
        for(int j=1;j<=i;j++){
            if(j!=1) dp[i+2][j+2] += comb(j,2) * dp[i][j];
            if(j!=i) dp[i+2][j] += comb(i-j+1,2) * dp[i][j];
            dp[i+2][j+1] += comb(j-1, 1) * comb(i-j, 1) * dp[i][j] + dp[i][j];
        }
    }
    for(int j=1;j<=2*n+1;j++){
        cout << dp[2*n+1][j].val() << endl;
    }
    return 0;
}
0