Submission #685721

# Submission time Handle Problem Language Result Execution time Memory
685721 2023-01-24T22:07:05 Z Summers Beautiful row (IZhO12_beauty) C++14
0 / 100
93 ms 262144 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
long long a[100], b[100], dp[(1<<21)][23], n;

long long rec(long long mask, long long last)
{
    if(mask==((1<<n)-1)) return 1;

    if(last!=-1 && dp[mask][last]!=-1)return dp[mask][last];
    long long an=0;
    for(long long i=0;i<n;i++)
    {
        if(!(mask&(1<<i)))
        {
            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);

    long long 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;
        }

    }
    memset(dp,-1,sizeof(dp));
    ans+=rec(0,-1);

    cout<<ans<<endl;


}

Compilation message

beauty.cpp: In function 'int main()':
beauty.cpp:31:17: warning: unused variable 'j' [-Wunused-variable]
   31 |     long long i,j,t,p,p1, ans=0;
      |                 ^
beauty.cpp:31:19: warning: unused variable 't' [-Wunused-variable]
   31 |     long long i,j,t,p,p1, ans=0;
      |                   ^
# Verdict Execution time Memory Grader output
1 Runtime error 93 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -