/*
ID: samikgo1
TASK:
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<ll,ll> pll;
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define f first
#define s second
//#define x first
//#define y second
const int INF = INT32_MAX;
const ll modulo = 1e4;
//#define int ll
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("input.in","r",stdin);
// freopen("haybales.out","w",stdout);
ll n;
cin >> n;
vector<pair<ll,pair<ll,ll>>> arr(n);
auto countbit = [](ll a){
ll onesa = 0;
ll backa = a;
while(a){
if(a%3==1)onesa++;
a/=3;
}
return make_pair(bitset<32>(backa).count(),onesa);
};
for (int i = 0; i < n; i++) {
ll a;cin>>a;
arr[i].first = i;
arr[i].second = countbit(a);
}
ll ans = 0;
do{
for (ll i = 1; i < n; i++) {
if(arr[i].second.first!=arr[i-1].second.first and arr[i].second.second!=arr[i-1].second.second){
goto end;
}
}
ans++;
end:
continue;
}while(next_permutation(all(arr)));
cout << ans;
}
Compilation message
beauty.cpp: In function 'int32_t main()':
beauty.cpp:37:23: warning: comparison of integer expressions of different signedness: 'int' and 'll' {aka 'long long unsigned int'} [-Wsign-compare]
37 | for (int i = 0; i < n; i++) {
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
26 ms |
212 KB |
Output is correct |
7 |
Correct |
22 ms |
324 KB |
Output is correct |
8 |
Correct |
45 ms |
296 KB |
Output is correct |
9 |
Correct |
24 ms |
212 KB |
Output is correct |
10 |
Correct |
43 ms |
212 KB |
Output is correct |
11 |
Execution timed out |
3045 ms |
212 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |