# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
945958 | NourWael | 아름다운 순열 (IZhO12_beauty) | C++17 | 522 ms | 600 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
sort(a.begin(),a.end());
int ans = 0;
do {
bool f = 1;
for(int i=1; i<n; i++) {
if(two[a[i]]!=two[a[i-1]] && thre[a[i]]!=thre[a[i-1]]) { f = 0; break; }
}
if(f) ans++;
}
while(next_permutation(a.begin(),a.end()));
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |