結果
| 問題 |
No.2944 Sigma Partition Problem
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-10-21 14:02:49 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 119 ms / 4,000 ms |
| コード長 | 1,789 bytes |
| コンパイル時間 | 616 ms |
| コンパイル使用メモリ | 41,472 KB |
| 最終ジャッジ日時 | 2025-02-24 22:11:06 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 24 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:75:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
75 | scanf("%d", &tn);
| ~~~~~^~~~~~~~~~~
main.cpp:79:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
79 | scanf("%d%d%d", &op, &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 2944.cc: No.2944 Sigma Partition Problem - yukicoder
*/
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 4000;
const int MAX_K = 4000;
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 dp[MAX_N + 1][MAX_K + 1];
/* subroutines */
/* main */
int main() {
fill(dp[0], dp[0] + MAX_K + 1, 1);
for (int n = 1; n <= MAX_N; n++) {
dp[n][0] = 0;
for (int k = 1; k <= MAX_K; k++) {
dp[n][k] = dp[n][k - 1];
if (n >= k) dp[n][k] += dp[n - k][k];
}
}
int tn;
scanf("%d", &tn);
while (tn--) {
int op, n, k;
scanf("%d%d%d", &op, &n, &k);
printf("%d\n", (int)dp[n][k]);
}
return 0;
}
tnakao0123