QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#859975 | #9967. Imbalanced Teams | lzm0107 | WA | 12ms | 13408kb | C++14 | 1.4kb | 2025-01-18 09:11:35 | 2025-01-18 09:11:35 |
Judging History
answer
#include <bits/stdc++.h>
#define lzm0107
using namespace std;
using LL = long long;
using AI2 = array<int, 2>;
using PII = pair<int, int>;
using ULL = unsigned long long;
const int N = 1e6 + 10, P = 1e9 + 7, INV2 = 500000004;
int n, k, a[N], fact[N], finv[N];
map<int, int> mp1, mp2, mp3;
int inv(int a){
int res = 1;
for(int i = P - 2; i; i >>= 1, a = 1ll * a * a % P) if(i & 1) res = 1ll * res * a % P;
return res;
}
int C(int n, int m){return 1ll * fact[n] * finv[m] % P * finv[n - m] % P;}
int main(){
ios::sync_with_stdio(false);
*cin.tie(nullptr) << fixed << setprecision(20);
fact[0] = 1;
for(int i = 1; i <= 1000000; i ++ ) fact[i] = 1ll * fact[i - 1] * i % P;
finv[1000000] = inv(fact[1000000]);
for(int i = 999999; i >= 0; i -- ) finv[i] = 1ll * finv[i + 1] * (i + 1) % P;
cin >> n >> k;
for(int i = 1; i <= n; i ++ ){
cin >> a[i];
mp1[a[i]] ++ ;
}
sort(a + 1, a + n + 1);
LL sum1 = 0, sum2 = 0;
for(int i = 1; i <= k; i ++ ) sum1 += a[i], mp2[a[i]] ++ ;
for(int i = n; i >= n - k + 1; i -- ) sum2 += a[i], mp3[a[i]] ++ ;
cout << sum2 - sum1 << ' ';
int ans2 = 1;
for(auto i : mp2){
ans2 = 1ll * ans2 * C(mp1[i.first], i.second) % P;
mp1[i.first] -= i.second;
}
for(auto i : mp3){
ans2 = 1ll * ans2 * C(mp1[i.first], i.second) % P;
mp1[i.first] -= i.second;
if(mp2[i.first] == i.second) ans2 = 1ll * ans2 * INV2 % P;
}
cout << ans2 << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 10ms
memory: 11744kb
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: 10ms
memory: 13408kb
input:
5 2 1 1 1 1 1
output:
0 15
result:
ok 2 number(s): "0 15"
Test #3:
score: 0
Accepted
time: 9ms
memory: 13404kb
input:
2 1 1 1
output:
0 1
result:
ok 2 number(s): "0 1"
Test #4:
score: 0
Accepted
time: 9ms
memory: 12000kb
input:
2 1 1 2
output:
1 1
result:
ok 2 number(s): "1 1"
Test #5:
score: 0
Accepted
time: 8ms
memory: 12384kb
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: 9ms
memory: 12764kb
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: 12ms
memory: 13284kb
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: 9ms
memory: 11748kb
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: 10ms
memory: 13156kb
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: 0
Accepted
time: 10ms
memory: 12256kb
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 36237869
result:
ok 2 number(s): "0 36237869"
Test #11:
score: 0
Accepted
time: 9ms
memory: 12644kb
input:
2000 1000 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834985 834...
output:
95671357 1001
result:
ok 2 number(s): "95671357 1001"
Test #12:
score: 0
Accepted
time: 6ms
memory: 12384kb
input:
2000 1000 999763 998795 997229 996607 995585 995585 995080 995080 995080 994251 994251 994251 994169 994158 994051 993410 993410 993410 993410 993410 993410 993410 993410 992448 992314 992176 990170 989664 989638 987205 987205 987205 987205 987205 987205 987067 986997 986233 985924 985707 985180 985...
output:
85351652 417058531
result:
ok 2 number(s): "85351652 417058531"
Test #13:
score: 0
Accepted
time: 10ms
memory: 11872kb
input:
2000 1000 220336 697950 570674 245907 697950 409648 697950 245907 697950 245907 245907 245907 496369 697950 697950 697950 245907 435446 697950 245907 697950 245907 697950 317643 245907 245907 697950 697950 697950 245907 697950 697950 697950 697950 697950 220336 412219 697950 245907 245907 697950 697...
output:
406826343 1001
result:
ok 2 number(s): "406826343 1001"
Test #14:
score: -100
Wrong Answer
time: 10ms
memory: 12768kb
input:
2000 1000 824739 824739 511894 511894 511894 824739 824739 511894 511894 511894 511894 511894 824739 511894 422607 824739 824739 824739 511894 824739 824739 824739 824739 824739 511894 824739 824739 824739 824739 824739 824739 511894 511894 824739 511894 824739 511894 824739 511894 824739 511894 824...
output:
312778791 1
result:
wrong answer 2nd numbers differ - expected: '2', found: '1'