QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#796708#9116. DRD StringrgnerdplayerAC ✓12ms16864kbC++233.3kb2024-12-02 00:24:112024-12-02 00:24:12

Judging History

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

  • [2024-12-02 00:24:12]
  • 评测
  • 测评结果:AC
  • 用时:12ms
  • 内存:16864kb
  • [2024-12-02 00:24:11]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

template <int P>
struct Modint {
    int v;

    constexpr Modint() : v(0) {}
    constexpr Modint(i64 v_) : v(v_ % P) {
        if (v < 0) {
            v += P;
        }
    }
    constexpr explicit operator int() const { return v; }
    constexpr friend ostream& operator<<(ostream &out, Modint n) {
        return out << int(n);
    }
    constexpr friend istream& operator>>(istream &in, Modint &n) {
        i64 v;
        in >> v;
        n = Modint(v);
        return in;
    }

    constexpr friend bool operator==(Modint a, Modint b) {
        return a.v == b.v;
    }
    constexpr friend bool operator!=(Modint a, Modint b) {
        return a.v != b.v;
    }

    constexpr Modint operator-() {
        Modint res;
        res.v = v ? P - v : 0;
        return res;
    }

    constexpr Modint& operator++() {
        v++;
        if (v == P) v = 0;
        return *this;
    }
    constexpr Modint& operator--() {
        if (v == 0) v = P;
        v--;
        return *this;
    }
    constexpr Modint& operator+=(Modint o) {
        v -= P - o.v;
        v = (v < 0) ? v + P : v;
        return *this;
    }
    constexpr Modint& operator-=(Modint o) {
        v -= o.v;
        v = (v < 0) ? v + P : v;
        return *this;
    }
    constexpr Modint& operator*=(Modint o) {
        v = 1LL * v * o.v % P;
        return *this;
    }
    constexpr Modint& operator/=(Modint o) { return *this *= o.inv(); }

    constexpr friend Modint operator++(Modint &a, int) {
        Modint r = a;
        ++a;
        return r;
    }
    constexpr friend Modint operator--(Modint &a, int) {
        Modint r = a;
        --a;
        return r;
    }

    constexpr friend Modint operator+(Modint a, Modint b) {
        return Modint(a) += b;
    }
    constexpr friend Modint operator-(Modint a, Modint b) {
        return Modint(a) -= b;
    }
    constexpr friend Modint operator*(Modint a, Modint b) {
        return Modint(a) *= b;
    }
    constexpr friend Modint operator/(Modint a, Modint b) {
        return Modint(a) /= b;
    }

    constexpr Modint qpow(i64 p) {
        Modint res = 1, x = v;
        while (p > 0) {
            if (p & 1) { res *= x; }
            x *= x;
            p >>= 1;
        }
        return res;
    }
    constexpr Modint inv() {
        return qpow(P - 2);
    }
};

constexpr int P = 998244353;
using Mint = Modint<P>;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    auto solve = [&]() {
        int n, m;
        cin >> n >> m;

        vector<Mint> pw(n + 1), ipw(n + 1);
        Mint im = Mint(m).inv();
        pw[0] = ipw[0] = 1;
        for (int i = 1; i <= n; i++) {
            pw[i] = pw[i - 1] * m;
            ipw[i] = ipw[i - 1] * im;
        }

        vector<Mint> dp(n + 1), pref(n / 2 + 1);

        for (int i = 1; i <= n; i++) {
            dp[i] = pw[i] - pref[i / 2] * pw[i];
            if (i <= n / 2) {
                pref[i] = pref[i - 1] + dp[i] * ipw[2 * i];
            }
        }

        Mint ans = pw[n] - dp[n];
        if (n % 2 == 0) {
            ans -= dp[n / 2];
        }

        cout << ans << '\n';
    };
    
    solve();
    
    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 2

output:

40

result:

ok "40"

Test #2:

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

input:

3017 7801

output:

515391664

result:

ok "515391664"

Test #3:

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

input:

3 1

output:

1

result:

ok "1"

Test #4:

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

input:

4 7

output:

343

result:

ok "343"

Test #5:

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

input:

5 4

output:

304

result:

ok "304"

Test #6:

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

input:

8 8

output:

2355200

result:

ok "2355200"

Test #7:

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

input:

7 6

output:

54216

result:

ok "54216"

Test #8:

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

input:

1330 3031

output:

139921223

result:

ok "139921223"

Test #9:

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

input:

4946 3837

output:

64102067

result:

ok "64102067"

Test #10:

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

input:

4236 3305

output:

78581604

result:

ok "78581604"

Test #11:

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

input:

399 3245

output:

714500544

result:

ok "714500544"

Test #12:

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

input:

4881 2346

output:

28365995

result:

ok "28365995"

Test #13:

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

input:

4647 3069

output:

798067847

result:

ok "798067847"

Test #14:

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

input:

3414 4280

output:

669878613

result:

ok "669878613"

Test #15:

score: 0
Accepted
time: 4ms
memory: 16864kb

input:

1000000 1000000

output:

469217978

result:

ok "469217978"

Test #16:

score: 0
Accepted
time: 4ms
memory: 16836kb

input:

1000000 1

output:

1

result:

ok "1"

Test #17:

score: 0
Accepted
time: 3ms
memory: 8836kb

input:

418909 302156

output:

189551565

result:

ok "189551565"

Test #18:

score: 0
Accepted
time: 4ms
memory: 16644kb

input:

984572 895728

output:

567020798

result:

ok "567020798"

Test #19:

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

input:

50545 723857

output:

651400574

result:

ok "651400574"

Test #20:

score: 0
Accepted
time: 4ms
memory: 12264kb

input:

668791 286918

output:

27505324

result:

ok "27505324"

Test #21:

score: 0
Accepted
time: 7ms
memory: 15376kb

input:

898539 238506

output:

9072376

result:

ok "9072376"

Test #22:

score: 0
Accepted
time: 9ms
memory: 12796kb

input:

711024 686568

output:

221989803

result:

ok "221989803"

Test #23:

score: 0
Accepted
time: 7ms
memory: 16292kb

input:

970385 660016

output:

104842944

result:

ok "104842944"

Test #24:

score: 0
Accepted
time: 7ms
memory: 16180kb

input:

943632 224593

output:

631779281

result:

ok "631779281"

Test #25:

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

input:

26758 836991

output:

860673946

result:

ok "860673946"

Test #26:

score: 0
Accepted
time: 7ms
memory: 14512kb

input:

838661 823355

output:

34634389

result:

ok "34634389"

Test #27:

score: 0
Accepted
time: 4ms
memory: 15840kb

input:

923587 8580

output:

549615557

result:

ok "549615557"

Test #28:

score: 0
Accepted
time: 4ms
memory: 7072kb

input:

275456 449218

output:

745638801

result:

ok "745638801"

Test #29:

score: 0
Accepted
time: 2ms
memory: 4588kb

input:

96512 594328

output:

159367796

result:

ok "159367796"

Test #30:

score: 0
Accepted
time: 12ms
memory: 16824kb

input:

995445 996221

output:

785170205

result:

ok "785170205"

Test #31:

score: 0
Accepted
time: 10ms
memory: 14348kb

input:

821123 195922

output:

950462887

result:

ok "950462887"

Test #32:

score: 0
Accepted
time: 9ms
memory: 13032kb

input:

715365 748511

output:

571984302

result:

ok "571984302"

Test #33:

score: 0
Accepted
time: 5ms
memory: 15036kb

input:

867858 338674

output:

698272834

result:

ok "698272834"

Test #34:

score: 0
Accepted
time: 6ms
memory: 8600kb

input:

406213 206504

output:

201893603

result:

ok "201893603"

Test #35:

score: 0
Accepted
time: 6ms
memory: 13356kb

input:

729455 262034

output:

521537323

result:

ok "521537323"

Test #36:

score: 0
Accepted
time: 7ms
memory: 15568kb

input:

915061 381221

output:

361349035

result:

ok "361349035"

Test #37:

score: 0
Accepted
time: 6ms
memory: 8860kb

input:

426669 32501

output:

206011209

result:

ok "206011209"

Test #38:

score: 0
Accepted
time: 4ms
memory: 6896kb

input:

256786 708325

output:

287335753

result:

ok "287335753"

Extra Test:

score: 0
Extra Test Passed