QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#715241#8834. Formal FringIllusionaryWhiteTravelerAC ✓63ms7536kbC++201.2kb2024-11-06 11:01:282024-11-06 11:01:29

Judging History

你现在查看的是最新测评结果

  • [2024-11-06 11:01:29]
  • 评测
  • 测评结果:AC
  • 用时:63ms
  • 内存:7536kb
  • [2024-11-06 11:01:28]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1000000 + 5;
const int P = 998244353;

int N, M, f[MAX_N], g[20];

inline int add(int a, int b) {return a + b < P ? a + b : a + b - P;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    
    cin >> N;
    for (M = 0; (1 << M + 1) <= N; M ++);
    f[0] = 1;
    for (int i = 0; i <= M; i ++) {
        int k = 1 << i;
        for (int j = 0; j + k <= N; j ++) {
            f[j + k] = add(f[j + k], f[j]);
        }
    }
    for (int i = 1; i <= M; i ++) {
        g[i] = f[(1 << i) - 1];
        for (int j = 1; j < i; j ++) {
            g[i] = (g[i] - 1ll * f[(1 << j) - 1] * g[i - j] + 1ll * P * P) % P;
        }
    }
    for (int i = 1, j, k; i <= N; i ++) {
        int ans = 0;
        for (j = M; ~ i >> j & 1; j --);
        for (k = j; k >= 0 && i >> k & 1; k --);
        if (k < 0) {
            ans = f[i];
        }else {
            for (k ++; k <= j; k ++) {
                ans = (ans + 1ll * f[i & (1 << k) - 1] * g[j - k + 1]) % P;
            }
        }
        cout << ans << "\n "[i < N];
    }
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3660kb

input:

10

output:

1 1 2 1 1 3 6 1 1 2

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 3596kb

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: 63ms
memory: 7536kb

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