# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
685718 | Summers | Beautiful row (IZhO12_beauty) | C++14 | 121 ms | 262144 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>
#include<vector>
#define endl '\n'
using namespace std;
int a[1000], b[1000], dp[(1<<20)][23], n;
int rec(int mask, int last)
{
if(mask==((1<<n)-1)) return 1;
if(last!=-1 && dp[mask][last]!=0)return dp[mask][last];
int an=0;
for(int i=0;i<n;i++)
{
if((mask&(1<<i))!=1)
{
if(last==-1 || a[last]==a[i] || b[last]==b[i])
{
an+=rec(mask|(1<<i), i);
}
}
}
return dp[mask][last]=an;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int i,j,t,p,p1, ans=0;
cin>>n;
for(i=0;i<n;i++)
{
cin>>p;
a[i]=__builtin_popcount(p);
p1=p;
while(p1>0)
{
if(p1%3==1)b[i]++;
p1/=3;
}
}
ans+=rec(0,-1);
cout<<ans<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |