# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
691825 | iskhakkutbilim | 아름다운 순열 (IZhO12_beauty) | C++14 | 8 ms | 16724 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
int ones(int x){
int s = 0;
while(x > 0){
s+= (x%3==1);
x/= 3;
}
return s;
}
int all[1<<20];
main(){
int n;
cin >> n;
vector<int> a(n), binary(n), ternary(n);
for(int i = 0;i < n; i++){
cin >> a[i];
binary[i] = __builtin_popcount(a[i]);
ternary[i] = ones(a[i]);
// cout << binary[i] << ' ' << ternary[i] << '\n';
}
int answer = 0;
vector<int> b_used(1<<20, 0), t_used(1<<20, 0);
for(int mask = 0; mask < (1<< n); mask++){
set<int> st, st1, st2;
int B = 0, T = 0;
for(int i = 0;i < n; i++){
if(mask & (1<<i)){
st1.insert(binary[i]);
B+= (1<<i);
st.insert(binary[i]);
}else{
T+= (1<<i);
st2.insert(ternary[i]);
st.insert(ternary[i]);
}
}
// if(st.size() == 1 && all[mask]==0){
// all[mask] = 1;
// answer++;
// }
if(st1.size() == 1 and __builtin_popcount(B) > 1){
// cout << "binary ";
// for(int i = 0;i < n; i++){
// if(mask & (1<<i)){
// cout << a[i] << ' ';
// }
// }
// cout << '\n';
b_used[B] = 1;
answer++;
}
if(st2.size() == 1 and __builtin_popcount(T) > 1){
// cout << "ternary ";
// for(int i = 0;i < n; i++){
// if(mask & (1<<i)){
//
// }else{
// cout << a[i] << ' ';
// }
// }
// cout << '\n';
answer++;
t_used[T] = 1;
}
}
cout << answer;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |