# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
321199 | kshitij_sodani | Beautiful row (IZhO12_beauty) | C++14 | 833 ms | 164580 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.
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl '\n'
llo n;
llo it[30];
llo co[30];
llo co2[30];
llo dp[1<<20][20];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
for(llo i=0;i<n;i++){
cin>>it[i];
llo x=it[i];
while(it[i]>0){
llo xx=it[i]%3;
if(xx==1){
co[i]++;
}
it[i]-=xx;
it[i]/=3;
}
it[i]=x;
while(it[i]>0){
llo xx=it[i]%2;
if(xx==1){
co2[i]++;
}
it[i]-=xx;
it[i]/=2;
}
}
llo ans=0;
for(llo i=1;i<(1<<n);i++){
vector<llo> co3;
for(llo j=0;j<n;j++){
if(i&(1<<j)){
co3.pb(j);
}
}
if(co3.size()==1){
dp[i][co3[0]]=1;
}
else{
for(int jj=0;jj<co3.size();jj++){
int j=co3[jj];
for(auto k:co3){
if(co[k]==co[j] or co2[j]==co2[k]){
dp[i][j]+=dp[i-(1<<j)][k];
}
}
}
}
if(co3.size()==n){
for(llo j=0;j<n;j++){
ans+=dp[i][j];
}
}
}
/*for(int i=0;i<n;i++){
cout<<co[i]<<",,";
}
cout<<endl;
for(int i=0;i<n;i++){
cout<<co2[i]<<",,";
}
cout<<endl;
cout<<dp[7][0]<<":"<<dp[7][1]<<":"<<dp[7][2]<<endl;
cout<<dp[3][0]<<":"<<dp[3][1]<<endl;
cout<<dp[2][1]<<endl;*/
cout<<ans<<endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |