QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#803794 | #8834. Formal Fring | Galex | AC ✓ | 254ms | 141732kb | C++23 | 2.6kb | 2024-12-07 18:37:23 | 2024-12-07 18:37:25 |
Judging History
answer
#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define pii pair<int, int>
#define pll pair<LL, LL>
#define fi first
#define se second
#define mkp make_pair
#define sz(x) (int)x.size()
#define pb push_back
using namespace std;
bool Mst;
LL read() {
LL s = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : 1), ch = getchar();
while (ch >= '0' && ch <= '9')
s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
return s * f;
}
const int mod = 998244353;
int qpow(int a, int b) {
int res = 1;
while (b) {
if (b & 1)
res = (LL)res * a % mod;
a = (LL)a * a % mod, b >>= 1;
}
return res;
}
auto fplus = [](int x, int y) {return x + y < mod ? x + y : x + y - mod;};
auto fminus = [](int x, int y) {return x >= y ? x - y : x + mod - y;};
auto Fplus = [](int &x, int y) {x = fplus(x, y);};
auto Fminus = [](int &x, int y) {x = fminus(x, y);};
const int N = (1 << 20), MAXN = N + 5;
int fac[MAXN], inv[MAXN];
void init() {
fac[0] = 1;
for (int i = 1; i <= N; i++)
fac[i] = (LL)fac[i - 1] * i % mod;
inv[N] = qpow(fac[N], mod - 2);
for (int i = N; i; i--)
inv[i - 1] = (LL)inv[i] * i % mod;
}
int C(int n, int m) {
return n < m ? 0 : (LL)fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int g[MAXN];
int dp[20][MAXN], f[20][MAXN], ans[MAXN];
bool Med;
signed main() {
g[1] = 1;
for (int i = 2; i < N; i++) {
g[i] = g[i - 1];
if (i % 2 == 0) Fplus(g[i], g[i / 2]);
}
for (int i = 1; i < 20; i++) {
for (int j = 0; j <= i; j++)
for (int k = 1; k * (1 << j) < (1 << (i + 1)); k++) dp[j][k] = 0;
dp[i][1] = 1;
for (int j = i - 1; j >= 0; j--) {
int lim = 1 << (i - j + 1);
for (int k = lim - 1; k > 1; k--) {
int o = j > 0;
if ((k - o) & 1) continue;
if (k + 2 <= lim) dp[j][k] = dp[j][k + 2];
Fplus(dp[j][k], dp[j + 1][(k - o) / 2]);
}
}
for (int j = 1; j < (1 << (i + 1)); j++) f[i][j] = dp[0][j];
}
memset(dp, 0, sizeof dp);
for (int i = 0; i < N; i++) dp[0][i] = 1;
for (int i = 1; i < 20; i++)
for (int j = 0; j < N; j++) {
dp[i][j] = dp[i - 1][j];
if (j >= (1 << i)) Fplus(dp[i][j], dp[i][j - (1 << i)]);
}
for (int i = 1; i < N; i++) {
int r = __lg(i), l = r;
while (l >= 0 && (i >> l) & 1) l--;
ans[i] = g[i];
if (l < 0) continue;
int val = i & ((1 << l) - 1);
for (int j = 0; j < (1 << (r - l + 1)); j++)
Fminus(ans[i], 1ll * f[r - l][j] * dp[l][val + (1 << l) * j] % mod);
}
int n = read();
for (int i = 1; i <= n; i++) printf("%d%c", ans[i], " \n"[i == n]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 212ms
memory: 140512kb
input:
10
output:
1 1 2 1 1 3 6 1 1 2
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 208ms
memory: 141732kb
input:
70
output:
1 1 2 1 1 3 6 1 1 2 2 5 5 11 26 1 1 2 2 4 4 6 6 11 11 16 16 27 27 53 166 1 1 2 2 4 4 6 6 10 10 14 14 20 20 26 26 37 37 48 48 64 64 80 80 107 107 134 134 187 187 353 1626 1 1 2 2 4 4 6
result:
ok 70 numbers
Test #3:
score: 0
Accepted
time: 254ms
memory: 140920kb
input:
1000000
output:
1 1 2 1 1 3 6 1 1 2 2 5 5 11 26 1 1 2 2 4 4 6 6 11 11 16 16 27 27 53 166 1 1 2 2 4 4 6 6 10 10 14 14 20 20 26 26 37 37 48 48 64 64 80 80 107 107 134 134 187 187 353 1626 1 1 2 2 4 4 6 6 10 10 14 14 20 20 26 26 36 36 46 46 60 60 74 74 94 94 114 114 140 140 166 166 203 203 240 240 288 288 336 336 400 ...
result:
ok 1000000 numbers
Extra Test:
score: 0
Extra Test Passed