#include <stdio.h>
#define N_MAX 20
#define BIT_MAX 1048575
int N, M=1, A[N_MAX+1], B[N_MAX+1][N_MAX+1];
long long D[N_MAX+1][BIT_MAX+1], Ans;
int binaryOne(int num) {
int i, cnt=0;
for(i=1 ; i<=num ; i<<=1)
if(num&i)
cnt++;
return cnt;
}
int ternaryOne(int num) {
int cnt=0;
while(num) {
if(num%3==1)
cnt++;
num/=3;
}
return cnt;
}
void bitMask(int x, int y) {
int i;
for(i=1 ; i<=N ; i++)
if(B[x][i] && y&(1<<(i-1))) {
if(!D[i][y-(1<<(x-1))])
bitMask(i,y-(1<<(x-1)));
D[x][y]+=D[i][y-(1<<(x-1))];
}
}
int main(void) {
int i, j;
scanf("%d",&N);
for(i=1 ; i<=N ; i++)
scanf("%d",&A[i]);
for(i=1 ; i<=N ; i++)
for(j=1 ; j<=N ; j++)
if(i!=j && (binaryOne(A[i])==binaryOne(A[j]) || ternaryOne(A[i])==ternaryOne(A[j])))
B[i][j]=1;
for(i=1 ; i<=N ; i++) {
M<<=1;
D[i][1<<(i-1)]=1;
}
M--;
for(i=1 ; i<=N ; i++) {
bitMask(i,M);
Ans+=D[i][M];
}
printf("%lld",Ans);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
173116 KB |
Output is correct |
2 |
Correct |
0 ms |
173116 KB |
Output is correct |
3 |
Correct |
0 ms |
173116 KB |
Output is correct |
4 |
Correct |
0 ms |
173116 KB |
Output is correct |
5 |
Correct |
0 ms |
173116 KB |
Output is correct |
6 |
Correct |
0 ms |
173116 KB |
Output is correct |
7 |
Correct |
0 ms |
173116 KB |
Output is correct |
8 |
Correct |
0 ms |
173116 KB |
Output is correct |
9 |
Correct |
0 ms |
173116 KB |
Output is correct |
10 |
Correct |
0 ms |
173116 KB |
Output is correct |
11 |
Execution timed out |
3000 ms |
173112 KB |
Program timed out |
12 |
Execution timed out |
3000 ms |
173112 KB |
Program timed out |
13 |
Execution timed out |
3000 ms |
173112 KB |
Program timed out |
14 |
Execution timed out |
3000 ms |
173112 KB |
Program timed out |
15 |
Correct |
546 ms |
173116 KB |
Output is correct |
16 |
Execution timed out |
3000 ms |
173112 KB |
Program timed out |
17 |
Execution timed out |
3000 ms |
173112 KB |
Program timed out |
18 |
Execution timed out |
3000 ms |
173112 KB |
Program timed out |
19 |
Execution timed out |
3000 ms |
173112 KB |
Program timed out |
20 |
Correct |
2648 ms |
173116 KB |
Output is correct |