#include<iostream>
#include<algorithm>
using namespace std;
int n;
pair<pair<int,int>,pair<int,int>> a[25];
int calc_cnt2(int x)
{
int rez=0;
for(int i=0;i<30;i++)
{
if(((1<<i)&x))
rez++;
}
return rez;
}
int calc_cnt3(int x)
{
int rez=0;
while(x>0)
{
if(x%3==1)
rez++;
x/=3;
}
return rez;
}
signed main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].second.first;
a[i].first = {calc_cnt2(a[i].second.first), calc_cnt3(a[i].second.first)};
a[i].second.second=i;
}
sort(a+1,a+1+n);
long long rez=0;
do
{
rez++;
for(int i=1;i<n;i++)
{
if(a[i].first.first!=a[i+1].first.first && a[i].first.second!=a[i+1].first.second)
{
rez--;
break;
}
}
}while(next_permutation(a+1,a+1+n));
cout<<rez;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
39 ms |
348 KB |
Output is correct |
7 |
Correct |
33 ms |
344 KB |
Output is correct |
8 |
Correct |
59 ms |
348 KB |
Output is correct |
9 |
Correct |
38 ms |
344 KB |
Output is correct |
10 |
Correct |
61 ms |
344 KB |
Output is correct |
11 |
Execution timed out |
3048 ms |
348 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |