# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1121445 | ezzzay | Beautiful row (IZhO12_beauty) | C++14 | 1 ms | 336 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>
using namespace std;
#define ff first
#define ss second
#define pb push_back
const int N=3e5+5;
int a[N];
int bincnt(int n){
int p=0;
while(n>0){
p+=n%2;
n/=2;
}
return p;
}
int tercnt(int n){
int p=0;
while(n>0){
if(n%3==1)p++;
n/=3;
}
return p;
}
int bc[N],tc[N];
int dp[1048590][21];
signed main(){
int ans=0;
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
bc[i]=bincnt(a[i]);
tc[i]=tercnt(a[i]);
}
for(int i=0;i<n;i++){
dp[(1<<i)][i]=1;
}
for(int i=1;i<(1<<n);i++){
for(int j=0;j<n;j++){
if((1<<j)&i ==0)continue; // suuld avsn
for(int k=0;k<n;k++){
if((1<<k)&i==0 or k==j)continue;
if(bc[j]==bc[k] or tc[j]==tc[k]){
dp[i][k]+=dp[i-(1<<k)][j];
}
}
if(i+1==(1<<n))ans+=dp[i][j];
}
}
cout<<ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |