# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
894934 | raul2008487 | 아름다운 순열 (IZhO12_beauty) | C++17 | 3056 ms | 452 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define vl vector<ll>
#define fi first
#define se second
#define in insert
#define mpr make_pair
#define lg(x) __lg(x)
#define bpc(x) __builtin_popcount(x)
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;
const int mod = 998244353;
vl adj[25];
bool used[25];
ll ans, n;
void dfs(ll v, ll depth){
used[v] = 1;
if(depth == n){
ans++;
used[v] = 0;
return ;
}
for(auto edge: adj[v]){
if(!used[edge]){
dfs(edge, depth + 1);
}
}
used[v] = 0;
}
void solve()
{
ll i, j;
cin>>n;
vl a(n);
vector<pll> v(n);
for(i=0;i<n;i++){
cin>>a[i];
v[i].fi = bpc(a[i]);
ll lg = 20, cnt = 0, d = a[i];
while(d){
ll dv = pow(3, lg);
lg--;
if(dv > d){continue;}
ll df = d / dv;
cnt += (df == 1);
d %= dv;
}
v[i].se = cnt;
}
for(i=0;i<n;i++){
for(j = i+1;j<n;j++){
if(v[i].fi == v[j].fi || v[i].se == v[j].se){
adj[i].pb(j);
adj[j].pb(i);
}
}
}
for(i=0;i<n;i++){
dfs(i, 1);
}
cout << ans << endl;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//precomp();
ll tst=1;
//cin>>tst;
while(tst--){
solve();
}
}
/*
ok.
*/
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |