# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
486292 | Sho10 | Beautiful row (IZhO12_beauty) | C++17 | 1621 ms | 127680 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> //Andrei Alexandru a.k.a Sho
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define aint(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 998244353
#define PI 3.14159265359
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,check[25][25],dp[25][2000005],a[25],cnt[3][25];
int32_t main(){
CODE_START;
cin>>n;
for(ll i=0;i<n;i++)
{
cin>>a[i];
}
for(ll i=0;i<n;i++)
{
ll x=a[i];
while(x>0){
if(x%2==1){
cnt[1][i]++;
}
x/=2;
}
x=a[i];
while(x>0){
if(x%3==1){
cnt[2][i]++;
}
x/=3;
}
}
for(ll i=0;i<n;i++)
{
for(ll j=0;j<n;j++)
{
if(i!=j){
if(cnt[2][i]==cnt[2][j]){
check[i][j]=1;
check[j][i]=1;
}else if(cnt[1][i]==cnt[1][j]){
check[i][j]=1;
check[j][i]=1;
}
}
}
}
for(ll i=0;i<n;i++)
{
dp[i][(1ll<<(i))]=1;
}
for(ll mask=0;mask<(1ll<<n);mask++)
{
for(ll i=0;i<n;i++)
{
for(ll j=0;j<n;j++)
{
if(i==j){
continue;
}
if((1ll<<i)&mask==0){
continue;
}
if((1ll<<(j))&mask){
if(dp[i][mask-(1ll<<(j))]==0){
continue;
}
if(check[i][j]==0){
continue;
}
dp[j][mask]+=dp[i][mask-(1ll<<(j))];
}
}
}
}
ll ans=0;
for(ll i=0;i<n;i++)
{
ans+=dp[i][(1ll<<(n))-1];
// cout<<dp[i][(1ll<<(n))-1]<<' ';
}
cout<<ans<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |