QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#848683#9967. Imbalanced TeamsrgnerdplayerWA 1ms3864kbC++234.8kb2025-01-09 02:53:312025-01-09 02:53:32

Judging History

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

  • [2025-01-09 02:53:32]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3864kb
  • [2025-01-09 02:53:31]
  • 提交

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>;

struct Combinatorial {
    int n;
    vector<Mint> _fact;
    vector<Mint> _ifact;
    vector<Mint> _inv;
    
    Combinatorial() : n{0}, _fact{1}, _ifact{1}, _inv{0} {}
    Combinatorial(int n) : Combinatorial() {
        init(n);
    }
    
    void init(int m) {
        if (m <= n) return;
        _fact.resize(m + 1);
        _ifact.resize(m + 1);
        _inv.resize(m + 1);
        
        for (int i = n + 1; i <= m; i++) {
            _fact[i] = _fact[i - 1] * i;
        }
        _ifact[m] = _fact[m].inv();
        for (int i = m; i > n; i--) {
            _ifact[i - 1] = _ifact[i] * i;
            _inv[i] = _ifact[i] * _fact[i - 1];
        }
        n = m;
    }
    
    Mint fact(int m) {
        if (m > n) init(2 * m);
        return _fact[m];
    }
    Mint ifact(int m) {
        if (m > n) init(2 * m);
        return _ifact[m];
    }
    Mint inv(int m) {
        if (m > n) init(2 * m);
        return _inv[m];
    }
    Mint binom(int n, int m) {
        if (n < m || m < 0) return 0;
        return fact(n) * ifact(m) * ifact(n - m);
    }
} comb;

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

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

        vector<int> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }

        sort(a.begin(), a.end());

        auto get = [&](int x) {
            auto [l, r] = equal_range(a.begin(), a.end(), x);
            return pair(l - a.begin(), r - a.begin());
        };

        int diff = accumulate(a.end() - k, a.end(), 0) - accumulate(a.begin(), a.begin() + k, 0);
        cout << diff << ' ';

        int L = a[k - 1], R = a[n - k];
        Mint ways = 1;

        if (L == R) {
            auto [l, r] = get(L);
            int len = r - l, c0 = k - l, c1 = r - (n - k);
            ways = comb.binom(len, c0) * comb.binom(len - c0, c1);
            if (l == 0 && r == n) {
                ways /= 2;
            }
        } else {
            auto [l1, r1] = get(L);
            ways *= comb.binom(r1 - l1, k - l1);
            auto [l2, r2] = get(R);
            ways *= comb.binom(r2 - l2, r2 - (n - k));
        }

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

詳細信息

Test #1:

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

input:

6 2
2 5 7 2 5 2

output:

8 6

result:

ok 2 number(s): "8 6"

Test #2:

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

input:

5 2
1 1 1 1 1

output:

0 15

result:

ok 2 number(s): "0 15"

Test #3:

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

input:

2 1
1 1

output:

0 1

result:

ok 2 number(s): "0 1"

Test #4:

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

input:

2 1
1 2

output:

1 1

result:

ok 2 number(s): "1 1"

Test #5:

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

input:

10 4
3 3 1 2 4 6 2 4 4 1

output:

12 1

result:

ok 2 number(s): "12 1"

Test #6:

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

input:

14 3
57 57 57 57 57 57 57 57 57 57 57 57 57 57

output:

0 30030

result:

ok 2 number(s): "0 30030"

Test #7:

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

input:

13 5
858336 900782 858336 900782 900782 858336 900782 858336 858336 858336 858336 858336 52093

output:

976027 280

result:

ok 2 number(s): "976027 280"

Test #8:

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

input:

14 4
447923 447923 447923 211106 447923 447923 447923 447923 16966 447923 211106 515550 211106 211106

output:

1209035 224

result:

ok 2 number(s): "1209035 224"

Test #9:

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

input:

2000 935
57596 988638 30477 956599 52986 460052 987863 291984 947848 109335 541003 338365 939256 297365 926486 944912 700042 810595 412192 37130 343207 311311 681629 48155 319677 435667 731251 919378 254216 893282 661237 740159 787502 501360 517533 349880 565298 536545 192793 18666 425164 856977 536...

output:

493241703 1

result:

ok 2 number(s): "493241703 1"

Test #10:

score: -100
Wrong Answer
time: 1ms
memory: 3656kb

input:

2000 1000
101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101493 101...

output:

0 236399791

result:

wrong answer 2nd numbers differ - expected: '36237869', found: '236399791'