QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#305826#8009. Growing SequencesikefumyAC ✓1ms3812kbC++205.5kb2024-01-16 01:59:482024-01-16 01:59:48

Judging History

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

  • [2024-01-16 01:59:48]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3812kb
  • [2024-01-16 01:59:48]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define int128 __int128_t
#define pii128 pair<int128,int128>
const int inf = 1 << 30;
const ll linf = 1e18;
const ll mod = 998244353;
const db EPS = 1e-10;
const db pi = acos(-1);
template<class T> bool chmin(T& x, T y){
    if(x > y) {
        x = y;
        return true;
    } else return false;
}
template<class T> bool chmax(T& x, T y){
    if(x < y) {
        x = y;
        return true;
    } else return false;
}

// overload macro
#define CAT( A, B ) A ## B
#define SELECT( NAME, NUM ) CAT( NAME, NUM )

#define GET_COUNT( _1, _2, _3, _4, _5, _6 /* ad nauseam */, COUNT, ... ) COUNT
#define VA_SIZE( ... ) GET_COUNT( __VA_ARGS__, 6, 5, 4, 3, 2, 1 )

#define VA_SELECT( NAME, ... ) SELECT( NAME, VA_SIZE(__VA_ARGS__) )(__VA_ARGS__)

// rep(overload)
#define rep( ... ) VA_SELECT(rep, __VA_ARGS__)
#define rep2(i, n) for (int i = 0; i < int(n); i++)
#define rep3(i, a, b) for (int i = a; i < int(b); i++)
#define rep4(i, a, b, c) for (int i = a; i < int(b); i += c)

// repll(overload)
#define repll( ... ) VA_SELECT(repll, __VA_ARGS__)
#define repll2(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repll3(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define repll4(i, a, b, c) for (ll i = a; i < (ll)(b); i += c)

// rrep(overload)
#define rrep( ... ) VA_SELECT(rrep, __VA_ARGS__)    
#define rrep2(i, n) for (int i = n - 1; i >= 0; i--)
#define rrep3(i, a, b) for (int i = b - 1; i >= a; i--)
#define rrep4(i, a, b, c) for (int i = b - 1; i >= a; i -= c)

// rrepll(overload)
#define rrepll( ... ) VA_SELECT(rrepll, __VA_ARGS__)
#define rrepll2(i, n) for (ll i = (ll)(n) - 1; i >= 0ll; i--)
#define rrepll3(i, a, b) for (ll i = b - 1; i >= (ll)(a); i--)
#define rrepll4(i, a, b, c) for (ll i = b - 1; i >= (ll)(a); i -= c)

// for_earh
#define fore(e, v) for (auto&& e : v)

// vector
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

template<class T, T mod>
struct modint {
    T num;
    constexpr modint(T a = 0) : num((a % mod + mod) % mod) {}

    constexpr modint operator+ (const modint& rhs) const noexcept {
        return modint(*this) += rhs;
    }
    constexpr modint operator- (const modint& rhs) const noexcept {
        return modint(*this) -= rhs;
    }
    constexpr modint operator* (const modint& rhs) const noexcept {
        return modint(*this) *= rhs;
    }
    constexpr modint operator/ (const modint& rhs) const noexcept {
        return modint(*this) /= rhs;
    }

    constexpr modint& operator += (const modint& rhs) noexcept {
        num = (num + rhs.num) % mod;
        return *this;
    }
    constexpr modint& operator -= (const modint& rhs) noexcept {
        num = (num - rhs.num + mod) % mod;
        return *this;
    }
    constexpr modint& operator *= (const modint& rhs) noexcept {
        num = num * rhs.num % mod;
        return *this;
    }
    constexpr modint& operator /= (modint rhs) noexcept {
        assert(rhs.num != 0);
        T y = mod - 2;
        while (y > 0) {
            if (y & 1) *this *= rhs;
            rhs *= rhs;
            y /= 2;
        }
        return *this;
    }

    constexpr modint& operator++ () noexcept {
        *this += (modint)1;
        return *this;
    }
    constexpr modint& operator++ (int) noexcept {
        modint tmp = *this;
        ++*this;
        return tmp;
    }
    constexpr modint& operator-- () noexcept {
        *this -= (modint)1;
        return *this;
    }
    constexpr modint& operator-- (int) noexcept {
        modint tmp = *this;
        --*this;
        return tmp;
    }

    friend ostream &operator << (ostream& lhs, const modint& rhs) {
        lhs << rhs.num;
        return lhs;
    }
    
    friend istream &operator >> (istream& lhs, modint& rhs) {
        lhs >> rhs.num;
        rhs.num = (rhs.num % mod + mod) % mod;
        return lhs;
    }
};

using mint = modint<ll, mod>;

mint modpow(mint x, ll y) {
    if (y == 0) return 1;
    return modpow(x * x, y / 2) * (y & 1 ? x : 1);
}

// 見ている桁, 最小でどの桁から使う, 0: < or = 1: >
mint dp[70][70][2];
// cnt[i][j] := 1 << iまでを使って1 << jを作る方法
mint cnt[70][70];

int n;
ll c;
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin >> n >> c;
    c -= 1ll << (n - 1);
    if (c < 0) {
        cout << 0 << '\n';
        return 0;
    }

    rep (i, 60) rep (j, 60) {
        if (i > j) continue;
        else if (i == j) cnt[i][j] = 1;
        else {
            cnt[i][j] += cnt[i][j - 1];
            rep (x, min(i, j - 1)) {
                ll pre = 0;
                cnt[i][j] += cnt[x][j - 1] * cnt[i - x][j - x - 1];
            } 
        }
    }

    dp[0][0][0] = 1;
    rep (i, 60) rep (j, n) rep (x, 2) {
        int nc = c >> i & 1;
        rep (y, 2) {
            int nxt = y * 2 + x > nc * 2;
            if (y == 0) dp[i + 1][j][nxt] += dp[i][j][x];
            else {
                rep (z, j, min(n,i + 1)) {
                    dp[i + 1][z][nxt] += dp[i][j][x] * cnt[z - j][i - j];
                }
            }
        }
    }

    mint ans = 0;
    rep (j, 60) ans += dp[60][j][0];
    cout << ans << '\n';
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1 5

output:

5

result:

ok answer is '5'

Test #2:

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

input:

3 6

output:

4

result:

ok answer is '4'

Test #3:

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

input:

15 179

output:

0

result:

ok answer is '0'

Test #4:

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

input:

35 1234567887654321

output:

576695683

result:

ok answer is '576695683'

Test #5:

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

input:

45 228228228

output:

0

result:

ok answer is '0'

Test #6:

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

input:

60 576460752303423487

output:

0

result:

ok answer is '0'

Test #7:

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

input:

60 576460752303423488

output:

1

result:

ok answer is '1'

Test #8:

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

input:

1 1000000000000000000

output:

716070898

result:

ok answer is '716070898'

Test #9:

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

input:

1 1

output:

1

result:

ok answer is '1'

Test #10:

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

input:

15 1

output:

0

result:

ok answer is '0'

Test #11:

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

input:

1 964573170374708959

output:

695628865

result:

ok answer is '695628865'

Test #12:

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

input:

2 336

output:

28224

result:

ok answer is '28224'

Test #13:

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

input:

5 463

output:

172916212

result:

ok answer is '172916212'

Test #14:

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

input:

7 75427

output:

523581579

result:

ok answer is '523581579'

Test #15:

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

input:

10 28166

output:

145818175

result:

ok answer is '145818175'

Test #16:

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

input:

12 77890

output:

724302124

result:

ok answer is '724302124'

Test #17:

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

input:

3 401245

output:

68076875

result:

ok answer is '68076875'

Test #18:

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

input:

8 511955

output:

109524351

result:

ok answer is '109524351'

Test #19:

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

input:

15 484969

output:

99426993

result:

ok answer is '99426993'

Test #20:

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

input:

30 779369

output:

0

result:

ok answer is '0'

Test #21:

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

input:

17 638679755

output:

132031375

result:

ok answer is '132031375'

Test #22:

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

input:

25 669522429

output:

896585516

result:

ok answer is '896585516'

Test #23:

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

input:

29 748278478

output:

563047844

result:

ok answer is '563047844'

Test #24:

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

input:

33 642978862039931

output:

550967529

result:

ok answer is '550967529'

Test #25:

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

input:

38 218051542638139

output:

29411033

result:

ok answer is '29411033'

Test #26:

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

input:

44 188775063557057

output:

185410072

result:

ok answer is '185410072'

Test #27:

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

input:

48 4677253159871213

output:

863467586

result:

ok answer is '863467586'

Test #28:

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

input:

22 854279883518523144

output:

916505804

result:

ok answer is '916505804'

Test #29:

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

input:

38 730620861826239715

output:

433138392

result:

ok answer is '433138392'

Test #30:

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

input:

54 435826341367976434

output:

237455633

result:

ok answer is '237455633'

Test #31:

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

input:

55 536518888651224157

output:

665085880

result:

ok answer is '665085880'

Test #32:

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

input:

56 413839394784728775

output:

647247529

result:

ok answer is '647247529'

Test #33:

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

input:

57 514531937773009201

output:

425329246

result:

ok answer is '425329246'

Test #34:

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

input:

58 391852448201481116

output:

522300883

result:

ok answer is '522300883'

Test #35:

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

input:

59 492544995484728838

output:

937899244

result:

ok answer is '937899244'

Test #36:

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

input:

60 693597573066212298

output:

490610488

result:

ok answer is '490610488'

Test #37:

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

input:

60 1000000000000000000

output:

13328531

result:

ok answer is '13328531'

Extra Test:

score: 0
Extra Test Passed