# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
90111 | Hideo | 아름다운 순열 (IZhO12_beauty) | C++14 | 2 ms | 484 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 27;
const int INF = 1e9 + 7;
vector < int > g[N];
int a[N], b[N], t[N];
int us[N], nd[N];
int n, ans;
int make_bin (int x, int c){
if (x == 0)
return c;
if (x % 2 == 1)
c++;
return make_bin (x / 2, c);
}
int make_ter (int x, int c){
if (x == 0)
return c;
if (x % 3 == 1)
c++;
return make_ter(x / 3, c);
}
void dfs (int v, int c){
us[v]++;
if (c == n){
ans++;
return;
}
for (int i = 0; i < g[v].size(); i++){
int to = g[v][i];
if (us[to] != nd[to])
dfs(to, c + 1);
}
nd[v]++;
}
main(){
cin >> n;
for (int i = 0; i < n; i++){
cin >> a[i];
b[i] = make_bin(a[i], 0);
t[i] = make_ter(a[i], 0);
}
for (int i = 0; i < n; i++){
for (int j = i + 1; j < n; j++){
if (b[i] == b[j] || t[i] == t[j]){
g[i].push_back(j);
g[j].push_back(i);
}
}
}
for (int i = 0; i < n; i++){
fill (nd, nd + N, 1);
fill (us, us + N, 0);
dfs(i, 1);
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |