QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#508106#7632. Balanced ArrayspandapythonerWA 158ms20348kbC++231.5kb2024-08-07 03:03:202024-08-07 03:03:20

Judging History

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

  • [2024-08-07 03:03:20]
  • 评测
  • 测评结果:WA
  • 用时:158ms
  • 内存:20348kb
  • [2024-08-07 03:03:20]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;


using ll = long long;

#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, n) for(int i = 0; i < n; i += 1)
#define len(a) ((int)(a).size())


const ll mod = 998244353;

ll bin_pow(ll x, ll n) {
    ll rs = 1;
    for (ll i = 1, a = x; i <= n; i *= 2, a = a * a % mod)
        if (n & i) rs = rs * a % mod;
    return rs;
}

ll inv(ll x) {
    return bin_pow(x, mod - 2);
}



vector<ll> f, rf;

void build_f(int n) {
    f.resize(n + 1);
    rf.resize(n + 1);
    f[0] = rf[0] = 1;
    for (int i = 1; i <= n; i += 1) {
        f[i] = (f[i - 1] * i) % mod;
        rf[i] = inv(f[i]);
    }
}

ll cnk(ll n, ll k) {
    return (f[n] * rf[k] % mod * rf[n - k] % mod);
}

ll catalan(ll n) {
    return cnk(2 * n, n) * inv(n + 1) % mod;
}


ll choose_repeating(ll n, ll k) {
    return cnk(n + k - 1, k);
}

int32_t main() {
    if (1) {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
    int n, m;
    cin >> n >> m;
    build_f(n + m + 1e5);
    ll result = (choose_repeating(m, n) + choose_repeating(2 * m + 1, n - 1)) % mod;
    for (int cnt = 1; 2 * cnt <= n and cnt <= m - 1; cnt += 1) {
        ll coeff = choose_repeating(m - 1, 2 * cnt) * catalan(cnt) % mod;
        result = (result + coeff * choose_repeating(2 * m + 1, n - 2 * cnt)) % mod;
    }
    cout << result << "\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 12ms
memory: 4688kb

input:

2 2

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: -100
Wrong Answer
time: 158ms
memory: 20348kb

input:

500000 500000

output:

70892753

result:

wrong answer 1st numbers differ - expected: '984531374', found: '70892753'