-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplete_this.cpp
More file actions
83 lines (73 loc) · 1.32 KB
/
complete_this.cpp
File metadata and controls
83 lines (73 loc) · 1.32 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
#include<bits/stdc++.h>
using namespace std;
int MOD=1e9+7;
#define MAX 312
int triangle[MAX + 1][MAX + 1];
vector<int> same;
map<int,int> s,ns;
int fact[312];
bool is_perfect_square(int n) {
if (n < 0)
return false;
int root(round(sqrt(n)));
return n == root * root;
}
void factorial()
{
fact[0] = fact[1] = 1;
for(int i=2;i<=310;i++)
{
fact[i] = (i * fact[i-1]) % MOD;
}
}
void makeTriangle() {
int i, j;
// initialize the first row
triangle[0][0] = 1; // C(0, 0) = 1
for(i = 1; i < MAX; i++) {
triangle[i][0] = 1; // C(i, 0) = 1
for(j = 1; j <= i; j++) {
triangle[i][j] = (triangle[i - 1][j - 1] + triangle[i - 1][j])%MOD;
}
}
}
int C(int n, int r) {
return triangle[n][r];
}
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
int temp;
cin>>temp;
if(is_perfect_square(temp))
{
if(s.find(temp)==s.end())
s[temp]=1;
else
s[temp]++;
}
else
{
if(ns.find(temp)==ns.end())
ns[temp]=1;
else
ns[temp]++;
}
}
//cout<<"here";
int result;
if(ns.size()>=s.size()-1)
{
result=C(n,s.size());
for(auto a: s)
result/=fact[a.second];
for(auto a: ns)
result/fact[a.second];
cout<<result<<endl;
}
else
cout<<"0"<<endl;
}