Submission #83153

# Submission time Handle Problem Language Result Execution time Memory
83153 2018-11-05T19:02:41 Z nikolapesic2802 Beautiful row (IZhO12_beauty) C++14
0 / 100
130 ms 164480 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define pb push_back

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; ///find_by_order(),order_of_key()
vector<vector<int> > graf(20);
int cnt2(int n)
{
    int c=0;
    while(n>0)
    {
        if(n%2==1)
            c++;
        n/=2;
    }
    return c;
}
int cnt3(int n)
{
    int c=0;
    while(n>0)
    {
        if(n%3==1)
            c++;
        n/=3;
    }
    return c;
}
ll dp[20][(1<<20)];

ll calc(int tr,int mask)
{
    //printf("Usao za %i %i\n",tr,mask);
    if(tr==0)
    {
        if(mask==0)
        {
            dp[tr][mask]=1;
        }
        else
        {
            dp[tr][mask]=0;
        }
    }
    if(dp[tr][mask]!=-1)
        return dp[tr][mask];
    dp[tr][mask]=0;
    for(auto p:graf[tr])
    {
        if((1<<p)&mask)
        {
            //printf("Pozivam za %i %i\n",p,1<<p);
            dp[tr][mask]+=calc(p,(1<<p)^mask);
        }
    }
    return dp[tr][mask];
}

int main()
{
    memset(dp,-1,sizeof(dp));
    vector<int> connect[32];
    int n;
    scanf("%i",&n);
    vector<int> niz(n);
    for(int i=0;i<n;i++)
    {
        scanf("%i",&niz[i]);
        int c2=cnt2(niz[i]);
        int c3=cnt3(niz[i]);
        connect[c2].pb(i);
        if(c2!=c3)
            connect[c3].pb(i);
    }
    for(int i=0;i<n;i++)
    {
        int c2=cnt2(niz[i]);
        int c3=cnt3(niz[i]);
        for(auto p:connect[c2])
        {
            if(p!=i)
            {
                //printf("%i -> %i\n",i,p);
                graf[i].pb(p);
            }
        }
        if(c2!=c3)
            for(auto p:connect[c3])
            {
                if(p!=i)
                {
                    //printf("%i -> %i\n",i,p);
                    graf[i].pb(p);
                }
            }
    }
    ll cnt=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            for(int m=0;m<(1<<(n-1));m++)
            {
                //printf("%i\n",m);
                int inverse=((1<<(n-1))-1)^m;
                int tr=m;
                tr<<=1;
                tr+=1;
                tr^=(1<<i);
                inverse<<=1;
                inverse+=1;
                inverse^=(1<<j);
                //if((ll)calc(i,m)*calc(j,inverse)>0)
                //printf("%lld %lld  %i-%i   %i-%i  %i\n",calc(i,tr),calc(j,inverse),i,tr,j,inverse,((1<<(n-1))-1));
                cnt+=(ll)calc(i,tr)*calc(j,inverse);
            }
        }
    }
    printf("%lld\n",cnt);
    return 0;
}

Compilation message

beauty.cpp: In function 'int main()':
beauty.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&n);
     ~~~~~^~~~~~~~~
beauty.cpp:74:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&niz[i]);
         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 130 ms 164464 KB Output is correct
2 Incorrect 130 ms 164480 KB Output isn't correct
3 Halted 0 ms 0 KB -