| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 691827 | iskhakkutbilim | 아름다운 순열 (IZhO12_beauty) | C++14 | 3058 ms | 300 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 a[21], binary[21], ternary[21], used[21];
map<int, int> order;
int n, answer;
int ones(int x){
int s = 0;
while(x > 0){
s+= (x%3==1);
x/= 3;
}
return s;
}
void f(int idx, int last){
if(idx == n){
answer++;
return;
}
for(int i = 0;i < n; i++){
if(used[i] == 0){
if(last == -1){
used[i] = 1;
f(idx+1, a[i]);
used[i] = 0;
}else{
if(binary[i] == binary[order[last]]){
used[i] = 1;
f(idx+1, a[i]);
used[i] = 0;
}else if(ternary[i] == ternary[order[last]]){
used[i] = 1;
f(idx+1, a[i]);
used[i] = 0;
}
}
}
}
}
main(){
cin >> n;
for(int i = 0;i < n; i++){
cin >> a[i];
order[a[i]] = i;
binary[i] = __builtin_popcount(a[i]);
ternary[i] = ones(a[i]);
}
f(0, -1);
cout << answer;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
