QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#851694 | #9967. Imbalanced Teams | ucup-team5071# | WA | 2ms | 5436kb | C++20 | 1.9kb | 2025-01-10 22:23:49 | 2025-01-10 22:23:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 100010;
const int mod = 1e9 + 7;
int ksm(int x, int k) {
int res = 1;
while (k) {
if (k & 1) res = res * x % mod;
x = x * x % mod;
k /= 2;
}
return res;
}
int ny(int x) { return ksm(x, mod - 2); }
void add(int &x, int y) {
if ((x += y) >= mod) x -= mod;
}
void del(int &x, int y) {
if ((x -= y) < 0) x += mod;
}
int inv[maxn], fac[maxn];
int C(int n, int m) {
return n == 0 ? 1 : fac[n] * inv[n - m] % mod * inv[m] % mod;
}
int A(int n, int m) { return n == 0 ? 1 : fac[n] * inv[n - m] % mod; }
void init() {
inv[0] = fac[0] = 1;
inv[1] = 1;
for (int i = 1; i < maxn; i++) {
fac[i] = fac[i - 1] * i % mod;
}
inv[1] = 1;
for (int i = 2; i < maxn; i++) {
inv[i] = (int)(mod - mod / i) * inv[mod % i] % mod;
}
inv[0] = 1;
for (int i = 1; i < maxn; i++) {
inv[i] = inv[i - 1] * inv[i] % mod;
}
}
signed main() {
ios::sync_with_stdio(false);
init();
int n, k;
cin >> n >> k;
vector<int> a(n);
map<int, int> ma;
for (int i = 0; i < n; i++) cin >> a[i], ma[a[i]]++;
sort(a.begin(), a.end());
int L = 0, R = 0;
int p, q;
{
int i = k - 1;
p = a[k - 1];
while (i >= 0 && a[i] == a[k - 1]) {
i--;
L++;
}
}
{
int i = n - k;
q = a[n - k];
while (i < n && a[i] == a[n - k]) {
i++;
R++;
}
}
cout << accumulate(a.end() - k, a.end(), 0ll) -
accumulate(a.begin(), a.begin() + k, 0ll)
<< " ";
if (p != q) {
cout << C(ma[p], L) * C(ma[q], R) % mod << "\n";
} else {
cout << C(ma[p], L + R) * C(L + R - 1, R - 1) % mod << "\n";
}
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 5200kb
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: 5140kb
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: 5200kb
input:
2 1 1 1
output:
0 1
result:
ok 2 number(s): "0 1"
Test #4:
score: 0
Accepted
time: 2ms
memory: 5436kb
input:
2 1 1 2
output:
1 1
result:
ok 2 number(s): "1 1"
Test #5:
score: 0
Accepted
time: 2ms
memory: 5364kb
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: 2ms
memory: 5148kb
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: -100
Wrong Answer
time: 2ms
memory: 5136kb
input:
13 5 858336 900782 858336 900782 900782 858336 900782 858336 858336 858336 858336 858336 52093
output:
976027 56
result:
wrong answer 2nd numbers differ - expected: '280', found: '56'