Skip to content

Commit b91e527

Browse files
committed
solved D2 Q2
1 parent 65a0ca1 commit b91e527

4 files changed

Lines changed: 61 additions & 1 deletion

File tree

Problems/Mathematics/Day-02/sol/Arnav_Singh/.cph/.Solution1.cpp_8a03896c340660fc53d23e6afdd07dd2.prob

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Local: Solution2","url":"\\\\wsl.localhost\\Ubuntu\\home\\arnav\\cp\\CP-Chronicles\\Problems\\Mathematics\\Day-02\\sol\\Arnav_Singh\\Solution2.cpp","tests":[{"id":1766903282354,"input":"","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"\\\\wsl.localhost\\Ubuntu\\home\\arnav\\cp\\CP-Chronicles\\Problems\\Mathematics\\Day-02\\sol\\Arnav_Singh\\Solution2.cpp","group":"local","local":true}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
long long fact[1005];
5+
const long long MOD = 1e9 + 7;
6+
void init() {
7+
fact[0] = 1;
8+
for (int i = 1; i <= 1000; i++)
9+
fact[i] = fact[i - 1] * i % MOD;
10+
}
11+
long long modpow(long long a, long long b) {
12+
long long res = 1;
13+
while (b) {
14+
if (b & 1) res = res * a % MOD;
15+
a = a * a % MOD;
16+
b >>= 1;
17+
}
18+
return res;
19+
}
20+
21+
int main() {
22+
init();
23+
int t;
24+
cin >> t;
25+
while(t--) {
26+
int n,k;
27+
cin>>n>>k;
28+
long long a[n];
29+
for (int i = 0; i < n; ++i) {
30+
cin>>a[i];
31+
}
32+
sort(a,a+n);
33+
reverse(a,a+n);
34+
long long repeat =a[k-1];
35+
int avl=0;
36+
unordered_map<long long,long long> m;
37+
for (int i = 0; i < k; ++i) {
38+
m[a[i]]++;
39+
}
40+
for (int i = 0; i < n; ++i) {
41+
if(a[i]==repeat){
42+
avl++;
43+
}
44+
}
45+
int ans=1;
46+
for(auto &[key,val]:m){
47+
if(key==repeat){
48+
ans = fact[avl] * modpow(fact[avl - val], MOD - 2) % MOD * modpow(fact[val], MOD - 2) % MOD;
49+
}
50+
else{
51+
ans*=1;
52+
}
53+
}
54+
cout << ans <<'\n';
55+
}
56+
57+
return 0;
58+
}
59+
//time complexity - O(nlogn)
60+
//https://codeforces.com/contest/1475/submission/355454659
206 KB
Binary file not shown.

0 commit comments

Comments
 (0)