結果
| 問題 |
No.2575 Almost Increasing Sequence
|
| コンテスト | |
| ユーザー |
noshi91
|
| 提出日時 | 2023-12-01 04:42:45 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,760 bytes |
| コンパイル時間 | 2,525 ms |
| コンパイル使用メモリ | 224,876 KB |
| 実行使用メモリ | 13,332 KB |
| スコア | 0 |
| 最終ジャッジ日時 | 2023-12-02 23:38:50 |
| 合計ジャッジ時間 | 25,123 ms |
|
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | TLE * 1 |
| other | -- * 19 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/modint>
using mint = atcoder::modint998244353;
static constexpr int N = 30000;
using poly = std::array<mint, N + 1>;
using coef = std::array<int, 3>;
using hp = std::map<coef, poly>;
coef add(coef c, int i) {
c[i]++;
return c;
}
coef proj(coef c, int i) {
c[i] = 0;
return c;
}
int main() {
int K;
std::cin >> K;
std::array<mint, N + 1> fact, ifact;
fact[0] = 1;
for (int i = 1; i <= N; i++)
fact[i] = fact[i - 1] * i;
ifact[N] = 1 / fact[N];
for (int i = N; i >= 1; i--)
ifact[i - 1] = ifact[i] * i;
std::map<coef, mint> pd;
pd[{0, 0, 0}] = 1;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 3; j++) {
// x_i - x_j
for (int k = 0; k < 2; k++) {
std::map<coef, mint> nx;
for (const auto& [c, v] : pd) {
nx[add(c, i)] += v;
nx[add(c, j)] -= v;
}
pd = std::move(nx);
}
}
}
for (auto it = pd.begin(); it != pd.end();) {
if (it->second == mint(0))
it = pd.erase(it);
else
++it;
}
poly ans;
std::array<hp, 3> dp;
for (int col = 0; col + 3 <= N; col++) {
for (int i = 1; i < 3; i++) {
int st = std::min(col * i, N + 1);
int w = std::min(i, N + 1 - st);
for (auto& [c, v] : dp[i]) {
std::copy_backward(v.begin() + st, v.end() - w, v.end());
std::fill(v.begin() + st, v.begin() + st + w, mint(0));
}
}
{
int h = (col + 1) * 3;
if (h < N + 1) {
std::array<mint, 7> pow;
pow[0] = 1;
for (int i = 1; i < 7; i++)
pow[i] = pow[i - 1] * (col + 1);
mint a = ifact[col + 1] * ifact[col + 1];
std::array<mint, 7> pc;
for (int j = 0; j < 7; j++)
pc[j] = a * pow[j];
for (const auto& [c, v] : pd) {
dp[2][proj(c, 2)][h] += pc[c[2]] * v;
}
}
}
poly temp;
for (int i = 1; i >= 0; i--) {
int h = (col + 1) * (i + 1);
if (h >= N + 1)
continue;
std::array<mint, 7> pow;
pow[0] = 1;
for (int t = 1; t < 7; t++)
pow[t] = pow[t - 1] * (col + 3 - i);
mint a = ifact[col + 3 - i] * ifact[col + 3 - i];
std::array<mint, 7> pc;
for (int j = 0; j < 7; j++)
pc[j] = a * pow[j];
for (const auto& [c, v] : dp[i + 1]) {
auto& t = i ? dp[i][proj(c, i)] : temp;
mint aa = pc[c[i]];
for (int k = h; k < N + 1; k++)
t[k] += aa * v[k];
}
}
mint a = mint(col + 1).pow(K);
for (int k = 0; k < N + 1; k++) {
ans[k] += a * temp[k];
}
}
std::cout << N << "\n";
for (int i = 1; i <= N; i++) {
std::cout << (ans[i] * fact[i] * fact[i]).val() << " \n"[i == N];
}
return 0;
}
noshi91