#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;
}
Compilation message
beauty.cpp: In function 'void dfs(int, int)':
beauty.cpp:39:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < g[v].size(); i++){
~~^~~~~~~~~~~~~
beauty.cpp: At global scope:
beauty.cpp:47:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Incorrect |
2 ms |
484 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |