QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#724194#5546. Sharing BreadKeeperHihiAC ✓0ms3708kbC++203.1kb2024-11-08 10:41:352024-11-08 10:41:36

Judging History

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

  • [2024-11-08 10:41:36]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3708kb
  • [2024-11-08 10:41:35]
  • 提交

answer

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

template<class T>
constexpr T power(T a, i64 b) {
    T res = 1;
    for (; b; b /= 2, a *= a) {
        if (b % 2) {
            res *= a;
        }
    }
    return res;
}

template<int P>
struct MInt {
    int x;
    constexpr MInt() : x{} {}
    constexpr MInt(i64 x) : x{norm(x % getMod())} {}
    
    static int Mod;
    constexpr static int getMod() {
        if (P > 0) {
            return P;
        } else {
            return Mod;
        }
    }
    constexpr static void setMod(int Mod_) {
        Mod = Mod_;
    }
    constexpr int norm(int x) const {
        if (x < 0) {
            x += getMod();
        }
        if (x >= getMod()) {
            x -= getMod();
        }
        return x;
    }
    constexpr int val() const {
        return x;
    }
    explicit constexpr operator int() const {
        return x;
    }
    constexpr MInt operator-() const {
        MInt res;
        res.x = norm(getMod() - x);
        return res;
    }
    constexpr MInt inv() const {
        assert(x != 0);
        return power(*this, getMod() - 2);
    }
    constexpr MInt &operator*=(MInt rhs) & {
        x = 1LL * x * rhs.x % getMod();
        return *this;
    }
    constexpr MInt &operator+=(MInt rhs) & {
        x = norm(x + rhs.x);
        return *this;
    }
    constexpr MInt &operator-=(MInt rhs) & {
        x = norm(x - rhs.x);
        return *this;
    }
    constexpr MInt &operator/=(MInt rhs) & {
        return *this *= rhs.inv();
    }
    friend constexpr MInt operator*(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res *= rhs;
        return res;
    }
    friend constexpr MInt operator+(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res += rhs;
        return res;
    }
    friend constexpr MInt operator-(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res -= rhs;
        return res;
    }
    friend constexpr MInt operator/(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res /= rhs;
        return res;
    }
    friend constexpr istream &operator>>(istream &is, MInt &a) {
        i64 v;
        is >> v;
        a = MInt(v);
        return is;
    }
    friend constexpr ostream &operator<<(ostream &os, const MInt &a) {
        return os << a.val();
    }
    friend constexpr bool operator==(MInt lhs, MInt rhs) {
        return lhs.val() == rhs.val();
    }
    friend constexpr bool operator!=(MInt lhs, MInt rhs) {
        return lhs.val() != rhs.val();
    }
};

template<>
int MInt<0>::Mod = 998244353;

template<int V, int P>
constexpr MInt<P> CInv = MInt<P>(V).inv();

constexpr int P = 998244353;
using Z = MInt<P>;

void solve() {
	int n, m;
	cin >> n >> m;
	Z ans = Z(n - m + 1) * power(Z(n + 1), m - 1);
	cout << ans << "\n";
}

/*
1 * 1
1 * 2, 1 * 3
1 * 3, 2 * 4, 4 * 4
1 * 4, 3 * 5, 5 * 10, 5 * 25
5 ^ 6^0, 4 * 6, 3 * 6^2, 2 ^ 6^3, 6^4

*/

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int t = 1;
	// cin >> t;

	while (t--) {
		solve();
	}

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 3

output:

50

result:

ok single line: '50'

Test #2:

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

input:

10 1

output:

10

result:

ok single line: '10'

Test #3:

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

input:

2 2

output:

3

result:

ok single line: '3'

Test #4:

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

input:

1 1

output:

1

result:

ok single line: '1'

Test #5:

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

input:

277 277

output:

124662617

result:

ok single line: '124662617'

Test #6:

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

input:

426 1

output:

426

result:

ok single line: '426'

Test #7:

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

input:

200000 1

output:

200000

result:

ok single line: '200000'

Test #8:

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

input:

200000 200000

output:

950017432

result:

ok single line: '950017432'

Test #9:

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

input:

200000 100000

output:

280947286

result:

ok single line: '280947286'

Test #10:

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

input:

200000 84731

output:

211985425

result:

ok single line: '211985425'

Test #11:

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

input:

200000 124713

output:

716696526

result:

ok single line: '716696526'

Test #12:

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

input:

129179 49655

output:

506429515

result:

ok single line: '506429515'

Test #13:

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

input:

87518 26040

output:

808454539

result:

ok single line: '808454539'

Test #14:

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

input:

178355 10116

output:

361555714

result:

ok single line: '361555714'

Test #15:

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

input:

2 1

output:

2

result:

ok single line: '2'

Test #16:

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

input:

192733 52550

output:

67181038

result:

ok single line: '67181038'

Test #17:

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

input:

76689 36632

output:

717949287

result:

ok single line: '717949287'

Test #18:

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

input:

200000 9

output:

158524471

result:

ok single line: '158524471'

Test #19:

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

input:

200000 199998

output:

879727659

result:

ok single line: '879727659'

Test #20:

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

input:

199952 1

output:

199952

result:

ok single line: '199952'

Test #21:

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

input:

199947 199947

output:

339118685

result:

ok single line: '339118685'

Test #22:

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

input:

199956 99978

output:

135867461

result:

ok single line: '135867461'

Test #23:

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

input:

2 2

output:

3

result:

ok single line: '3'

Test #24:

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

input:

10 3

output:

968

result:

ok single line: '968'

Test #25:

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

input:

10 5

output:

87846

result:

ok single line: '87846'

Test #26:

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

input:

10 9

output:

428717762

result:

ok single line: '428717762'

Test #27:

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

input:

279 166

output:

945780025

result:

ok single line: '945780025'

Test #28:

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

input:

361 305

output:

926296326

result:

ok single line: '926296326'

Test #29:

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

input:

305 262

output:

465560336

result:

ok single line: '465560336'