#include <iostream>
#include <algorithm>
#include <map>
#include <array>
#define f first
#define s second
#define pii pair <int, int>
#define pb push_back
using namespace std;
const int N = 50 + 5;
int n, a[N], b[N], p[N], ans, good[N][N];
int ones3(int x) {
int cnt = 0;
while (x > 0) {
if (x % 3 == 1) cnt++;
x /= 3;
}
return cnt;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
p[i] = i;
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (__builtin_popcountll(a[i]) == __builtin_popcountll(a[j]) || ones3(a[i]) == ones3(a[j])) {
good[i][j] = good[j][i] = 1;
continue;
}
}
}
do {
for (int i = 1; i <= n; i++) {
b[i] = a[p[i]];
}
int bad = 0;
for (int i = 1; i < n; i++) {
if (!good[p[i]][p[i + 1]]) bad = 1;
}
if (!bad) ans++;
} while(next_permutation(p + 1, p + n + 1));
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 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 |
73 ms |
348 KB |
Output is correct |
7 |
Correct |
67 ms |
348 KB |
Output is correct |
8 |
Correct |
72 ms |
432 KB |
Output is correct |
9 |
Correct |
66 ms |
416 KB |
Output is correct |
10 |
Correct |
69 ms |
348 KB |
Output is correct |
11 |
Execution timed out |
3038 ms |
348 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |