結果
| 問題 |
No.2528 pop_(backfront or not)
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-06-19 18:42:30 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 187 ms / 2,000 ms |
| コード長 | 1,997 bytes |
| コンパイル時間 | 442 ms |
| コンパイル使用メモリ | 43,648 KB |
| 最終ジャッジ日時 | 2025-02-21 23:21:41 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:69:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
69 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 2528.cc: No.2528 pop_(backfront or not) - yukicoder
*/
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 2000;
const int MAX_N2 = MAX_N * 2;
const int MOD = 998244353;
/* typedef */
template<const int MOD>
struct MI {
int v;
MI(): v() {}
MI(int _v): v(_v % MOD) { if (v < 0) v += MOD; }
MI(long long _v): v(_v % MOD) { if (v < 0) v += MOD; }
explicit operator int() const { return v; }
MI operator+(const MI m) const { return MI(v + m.v); }
MI operator-(const MI m) const { return MI(v + MOD - m.v); }
MI operator*(const MI m) const { return MI((long long)v * m.v); }
MI &operator+=(const MI m) { return (*this = *this + m); }
MI &operator-=(const MI m) { return (*this = *this - m); }
MI &operator*=(const MI m) { return (*this = *this * m); }
bool operator==(const MI m) const { return v == m.v; }
bool operator!=(const MI m) const { return v != m.v; }
MI pow(int n) const { // a^n % MOD
MI pm = 1, a = *this;
while (n > 0) {
if (n & 1) pm *= a;
a *= a;
n >>= 1;
}
return pm;
}
MI inv() const { return pow(MOD - 2); }
MI operator/(const MI m) const { return *this * m.inv(); }
MI &operator/=(const MI m) { return (*this = *this / m); }
};
using mi = MI<MOD>;
/* global variables */
mi inv2 = mi(2).inv();
mi dp[MAX_N2 + 1][MAX_N2 + 1];
/* subroutines */
mi nc2(int n) { return mi(n) * (n - 1) * inv2; }
/* main */
int main() {
int n;
scanf("%d", &n);
int n2 = n * 2;
dp[0][0] = 1;
for (int l = 2; l <= n2; l += 2)
for (int i = 0, j = l - i; j >= 0; i++, j--) {
if (i > 0 && j > 0)
dp[i][j] += dp[i - 1][j - 1];
if (i >= 3)
dp[i][j] += dp[i - 2][j] * nc2(i - 1);
if (j >= 3)
dp[i][j] += dp[i][j - 2] * nc2(j - 1);
if (i >= 2 && j >= 2)
dp[i][j] += dp[i - 1][j - 1] * (mi(i - 1) * (j - 1));
}
for (int i = 0; i <= n2; i++)
printf("%d\n", (int)dp[i][n2 - i]);
return 0;
}
tnakao0123