forked from Sahaj-Bamba/HacktoberTrial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasd.cpp
More file actions
105 lines (93 loc) · 1.92 KB
/
asd.cpp
File metadata and controls
105 lines (93 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include<bits/stdc++.h>
using namespace std;
long long int facto(int n)
{
long long int ans=1;
for(long long int i=1;i<=n;i++)
{
ans*=i;
}
return ans;
}
int nCr(int n, int r)
{
return facto(n) / facto(n - r);
}
int solve(vector<int> &A, int B, int C) {
string str=to_string(C);
sort(A.begin(),A.end());
//map<int,int> mp;
if(B==1)
{
int count1=0;
for(int i=0;i<A.size();i++)
{
if(A[i]<C)
count1++;
}
return count1;
}
//for(int i=0;i<A.size();i++)
//{
// mp[A[i]]=i+1;
//}
if(B<(str.length()))
{ //cout<<"$$";
if(A[0]==0)
{
return (A.size()-1)*facto(A.size()-1);
}
else
{
return facto(A.size());
}
}
if(B>str.length())
return 0;
long long int ans=0;
vector<int> removed;
for(int i=0;i<str.length();i++)
{
int no=(int)(str[i]-'0');
// cout<<no<<" "<<ans<<"\n";
if(i==0)
{
if(A[0]==0)
{
ans=ans+(lower_bound(A.begin(), A.end(),no)-A.begin()-1)*(nCr(A.size(),B-i-1));
//cout<<lower_bound(A.begin(), A.end(),no)-A.begin()<<"\n";
}
else
{
ans=ans + (lower_bound(A.begin(), A.end(),no)-A.begin())*(nCr(A.size(),B-i-1));
}
}
else
{
/* int count=0;
for(int j=0;j<removed.size();j++)
{
if(removed[j]<no)
count++;
}*/
ans=ans+(lower_bound(A.begin(), A.end(),no)-A.begin())*(nCr(A.size(),B-i-1));
}
// removed.push_back(no);
}
return ans;
}
int main()
{
int n;
cin>>n;
vector<int> v(n);
for(int i=0;i<n;i++)
{
cin>>v[i];
}
int b;
cin>>b;
int c;
cin>>c;
cout<<solve(v,b,c)<<"\n";
}