QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#460551#8834. Formal Fringucup-team045AC ✓80ms10888kbC++203.1kb2024-07-01 20:23:482024-07-01 20:23:48

Judging History

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

  • [2024-07-01 20:23:48]
  • 评测
  • 测评结果:AC
  • 用时:80ms
  • 内存:10888kb
  • [2024-07-01 20:23:48]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<stdint.h>
using namespace std;
using LL = long long;
template<const int T>
struct ModInt {
    const static int mod = T;
    int x;
    ModInt(int x = 0) : x(x % mod) {}
    ModInt(long long x) : x(int(x % mod)) {} 
    int val() { return x; }
    ModInt operator + (const ModInt &a) const { int x0 = x + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
    ModInt operator - (const ModInt &a) const { int x0 = x - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }
    ModInt operator * (const ModInt &a) const { return ModInt(1LL * x * a.x % mod); }
    ModInt operator / (const ModInt &a) const { return *this * a.inv(); }
    bool operator == (const ModInt &a) const { return x == a.x; };
    bool operator != (const ModInt &a) const { return x != a.x; };
    void operator += (const ModInt &a) { x += a.x; if (x >= mod) x -= mod; }
    void operator -= (const ModInt &a) { x -= a.x; if (x < 0) x += mod; }
    void operator *= (const ModInt &a) { x = 1LL * x * a.x % mod; }
    void operator /= (const ModInt &a) { *this = *this / a; }
    friend ModInt operator + (int y, const ModInt &a){ int x0 = y + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
    friend ModInt operator - (int y, const ModInt &a){ int x0 = y - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }
    friend ModInt operator * (int y, const ModInt &a){ return ModInt(1LL * y * a.x % mod);}
    friend ModInt operator / (int y, const ModInt &a){ return ModInt(y) / a;}
    friend ostream &operator<<(ostream &os, const ModInt &a) { return os << a.x;}
    friend istream &operator>>(istream &is, ModInt &t){return is >> t.x;}

    ModInt pow(int64_t n) const {
        ModInt res(1), mul(x);
        while(n){
            if (n & 1) res *= mul;
            mul *= mul;
            n >>= 1;
        }
        return res;
    }
    
    ModInt inv() const {
        int a = x, b = mod, u = 1, v = 0;
        while (b) {
            int t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        if (u < 0) u += mod;
        return u;
    }
    
};
using mint = ModInt<998244353>;

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int n;
    cin >> n;
    vector<mint> f(n + 1);
    f[0] = f[1] = 1;
    for(int i = 2; i <= n; i++){
        f[i] = f[i - 2] + f[i >> 1];
    }
    vector<mint> dp(n + 1), g{0};
    for(int i = 1; (1 << i) - 1 <= n; i++){
        g.push_back(f[(1 << i) - 1]);
    }
    dp[0] = dp[1] = 1;
    for(int i = 2; i <= n; i++){
        int t = __lg(i);
        vector<mint> ways(t + 2);
        for(int j = t; j >= 0; j--){
            if (!(i >> j & 1)) break;
            int len = t - j + 1;
            ways[len] = g[len];
            for(int k = 1; k < len; k++){
                ways[len] -= ways[k] * f[((1 << (len - k)) - 1)];
            }
            dp[i] += ways[len] * f[i & ((1 << j) - 1)];
        }
    }
    for(int i = 1; i <= n; i++){
        cout << dp[i] << " \n"[i == n];
    }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3644kb

input:

10

output:

1 1 2 1 1 3 6 1 1 2

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 1ms
memory: 3476kb

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: 80ms
memory: 10888kb

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