# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1121447 | ezzzay | Beautiful row (IZhO12_beauty) | C++14 | 847 ms | 172792 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
#define int long long
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 a=0;a < n;a++){
if(i & (1<<a)){ // umnuhd ni orsn
for(int b=0;b<n;b++){
if(tc[b]!=tc[a] and bc[a]!=bc[b])continue;
if(((1<<b) & i) == 0){
dp[i | (1<<b)][b] = (dp[i|(1<<b)][b] + dp[i][a]) ;
}
}
}
}
}
for(int i=0;i<n;i++){
ans+=dp[(1<<n)-1][i];
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |