QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#73303 | #4812. Counting Sequence | LG_Monkey | ML | 0ms | 0kb | C++14 | 1.2kb | 2023-01-23 17:15:49 | 2023-01-23 17:15:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define mp make_pair
#define fi first
#define pb push_back
#define se second
#define ll long long
int n, c, f[300010][1210]; int** g;
const int mod = 998244353;
signed main() {
cin >> n >> c;
int len = 800;
for (int i = 1; i <= len; i++) f[i][i] = 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= min(1200, i); j++) {
if (i == j) continue;
f[i][j] += (ll)f[i - j][j + 1] * (ll)c % (ll)mod;
if (j >= 2) f[i][j] = ((ll)f[i][j] + (ll)f[i - j][j - 1]) % (ll)mod;
}
ll ans = 0;
for (int i = 1; i <= 1200; i++) (ans += f[n][i]) %= mod;
// delete[] f;
int **g = new int* [810];
for (int i = 0; i < 810; i++) g[i] = new int [600010];
for (int i = 1; i <= 800; i++)
for (int j = 0; j <= 600000; j++) {
int k = j - 300000;
if (i == 0 && k == 0) {
g[i][j] = 1; continue;
}
if (j - i + 1 >= 0) g[i][j] += g[i - 1][j - i + 1];
if (j + i - 1 <= 600000) g[i][j] += g[i - 1][j + i - 1] * c; g[i][j] %= mod;
}
for (int i = len + 1; i <= n; i++)
for (int j = 1; j <= 2005; j++)
(ans += g[j][n - i * j]) %= mod;
cout << ans << "\n";
return 0;
}
詳細信息
Test #1:
score: 0
Memory Limit Exceeded
input:
5 3