QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#462572 | #8834. Formal Fring | ucup-team2307# | AC ✓ | 196ms | 245920kb | C++20 | 1.6kb | 2024-07-03 21:14:06 | 2024-07-03 21:14:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
#define int ll
const int mod = 998244353;
const int N = 1e6+100;
const int K = 20;
signed all[N][K];
int ans[N][K];
int hb[N];
int f(int n, int k)
{
if (n==1)
return 1;
int h = hb[n];
k = min(k, h);
if (ans[n][k] != -1)
return ans[n][k];
int A = 0;
if (k >= h)
A = all[n-(1<<h)][k];
int r = n-(1<<h);
if (hb[r] != h-1)
{
return ans[n][k] = A;
}
int l = (1<<(h+1)) - n;
for (int y=hb[l]; y<=min(k, h-1); y++)
if ((1<<y) >= l)
for (int x=y; x<=min(k, h-1); x++)
{
int X = all[(1<<(h-1-x))-1][k-x];
int Y = all[(1<<(h-1-y))-1][x-y];
int Z = f(r, y);
A = (A+X*Y%mod*Z%mod)%mod;
}
return ans[n][k] = A;
}
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
for (int i=0; i<K; i++)
ans[0][i] = 1;
for (int i=1; i<N; i++)
for (int j=0; j<K; j++)
{
if (j>=1)
ans[i][j] = ans[i][j-1];
if (i>=(1<<j))
ans[i][j] = (ans[i][j] + ans[i-(1<<j)][j]) % mod;
}
for (int i=0; i<N; i++)
for (int j=0; j<K; j++)
all[i][j] = ans[i][j], ans[i][j] = -1;
hb[0] = -1;
for (int i=1; i<N; i++)
hb[i] = hb[i/2]+1;
int n;
cin>>n;
for (int i=1; i<=n; i++)
cout<<f(i, K-1)<<" ";
cout<<"\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 125ms
memory: 245900kb
input:
10
output:
1 1 2 1 1 3 6 1 1 2
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 124ms
memory: 245840kb
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: 196ms
memory: 245920kb
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