#include <bits/stdc++.h>
using namespace std;
map<int,int> two,thre;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin>>n;
vector<int> a;
for(int i=0; i<n; i++) {
int x; cin>>x;
a.push_back(x);
int cnt = 0;
while(x) {
cnt += (x&1);
x = x>>1;
}
two[a[i]] = cnt;
x = a[i], cnt = 0;
int b = 387420489;
while(x) {
if(b*2<=x) { x-=b*2; }
else if(b<=x) { x-=b; cnt++; }
b/=3;
}
thre[a[i]] = cnt;
}
vector<int> v;
for(int i=0; i<n; i++) v.push_back(i);
int ans = 0;
do {
bool f = 1;
for(int i=1; i<n; i++) {
if(two[a[v[i]]]!=two[a[v[i-1]]] && thre[a[v[i]]]!=thre[a[v[i-1]]]) { f = 0; break; }
}
if(f) ans++;
}
while(next_permutation(v.begin(),v.end()));
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
173 ms |
348 KB |
Output is correct |
7 |
Correct |
124 ms |
448 KB |
Output is correct |
8 |
Correct |
595 ms |
428 KB |
Output is correct |
9 |
Correct |
130 ms |
348 KB |
Output is correct |
10 |
Correct |
437 ms |
428 KB |
Output is correct |
11 |
Execution timed out |
3053 ms |
348 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |