#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;cin>>n;
vector<int> v(n);
vector<int> a(n),b(n);
for(int i=0;i<n;i++){
cin>>v[i];
}
for(int i=0;i<n;i++){
int p=v[i];
while(p>0){
if(p%3==1){
a[i]++;
}
p/=3;
}
p=v[i];
while(p>0){
if(p%2==1){
b[i]++;
}
p/=2;
}
}
vector<vector<int>> dp(n,vector<int>(1<<n));
for(int i=0;i<n;i++){
dp[i][1<<i]=1;
}
for(int i=1;i<(1<<n);i++){
for(int j=0;j<n;j++){
if(i&(1<<j)){
for(int k1=0;k1<n;k1++){
if(a[j]==a[k1]||b[j]==b[k1]){
dp[j][i]+=dp[k1][i-(1<<j)];
}
}
}
}
}
int ans=0;
for(int i=0;i<n;i++){
ans+=dp[i][(1<<n)-1];
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
316 KB |
Output is correct |
11 |
Incorrect |
5 ms |
1236 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |