# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1017923 | LM1 | Beautiful row (IZhO12_beauty) | C++14 | 427 ms | 180864 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define bin __builtin_popcount
#define ll long long
#define int long long
#define pb push_back
#define ff first
#define ss second
using namespace std;
const int N=22;
int fix[N][N],dp[(1<<N)][N];
int ter(int x){
int aa=0;
while(x>0){
if(x%3==1)aa++;
x/=3;
}
return aa;
}
main(){
int n;cin>>n;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(bin(a[i])==bin(a[j])){
fix[i][j]=1;
fix[j][i]=1;
continue;
}
if(ter(a[i])==ter(a[j])){
fix[i][j]=1;
fix[j][i]=1;
continue;
}
}
}
int ans=0;
for(int i=1;i<(1<<n);i++){
vector<int>v;
for(int j=0;j<n;j++)if((1<<j)&i)v.pb(j);
if(bin(i)==1){
dp[i][v[0]]=1;
continue;
}
for(int j=0;j<v.size();j++){
int l=v[j];
for(int k=0;k<v.size();k++){
int l1=v[k];
if(j==k)continue;
if(fix[l][l1])dp[i][l]+=dp[i^(1<<l)][l1];
}
if(i==(1<<n)-1)ans+=dp[i][l];
}
}
cout<<ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |