| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 339057 | scales | 아름다운 순열 (IZhO12_beauty) | C++17 | 2 ms | 364 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>
/*#ifndef LOCAL_RUN
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC optimize("fast-math")
    #pragma GCC target("avx2,tune=native")
#endif*/
using namespace std;
int dp[20][1100000];
int main()
{
        ios::sync_with_stdio(false);
        cin.tie(0);
        freopen("b.in","r",stdin);
        freopen("b.out","w",stdout);
    int i,j,y,z,m,k,x1,g,y1,sum,n,x,f,l,q,maxi,r,kol;
    vector<int > d(31),t(21);
    d[0]=1;
    t[0]=1;
    for(i=1;i<=30;i++)
    {
        d[i]=d[i-1]*2;
        //cout<<"d[i]="<<d[i]<<endl;
    }
    for(i=1;i<=17;i++)
    {
        t[i]=t[i-1]*3;
        //cout<<"t["<<i<<"]="<<t[i]<<endl;
    }
    cin>>n;
    vector<int> a(n),b(n),c(n);
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=0;
        c[i]=0;
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<=30;j++)
        {
            z=a[i]&d[j];
            if(z!=0)
            {
                b[i]++;
            }
        }
       // cout<<"b["<<i<<"]="<<b[i]<<endl;
    }
    for(i=0;i<n;i++)
    {
        for(j=20;j>=0;j--)
        {
            //cout<<"a["<<i<<"]="<<a[i]<<endl;
            if(a[i]>=2*t[j])
            {
                a[i]=a[i]-2*t[j];
            }
            else
            {
                if(a[i]>=t[j])
                {
                    c[i]++;
                    a[i]=a[i]-t[j];
                }
            }
        }
       // cout<<"c["<<i<<"]="<<c[i]<<endl;
    }
    //cout<<endl;
    int s[20][20];
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(c[i]==c[j] || b[i]==b[j])
            {
                s[i][j]=1;
            }
            else
            {
                s[i][j]=0;
            }
            //cout<<s[i][j]<<" ";
        }
        //cout<<endl;
    }
    for(i=0;i<n;i++)
    {
        dp[i][0]=0;
    }
    for(j=1;j<d[n];j++)
    {
        for(i=0;i<n;i++)
        {
                if(j==d[i])
                {
                    dp[i][j]=1;
                }
                else
                {
                    dp[i][j]=0;
                    z=j&d[i];
                    if(z!=0)
                    {
                        x=j-d[i];
                        //cout<<"x="<<x<<" ";
                        for(q=0;q<n;q++)
                        {
                            if(q!=i && s[q][i]==1)
                            {
                                z=j&d[q];
                                if(z!=0)
                                {
                                    dp[i][j]=dp[i][j]+dp[q][x];
                                }
                            }
                        }
                    }
                }
                //cout<<"dp["<<i<<"]["<<j<<"]="<<dp[i][j]<<endl;
        }
    }
    sum=0;
    for(i=0;i<n;i++)
    {
        sum=sum+dp[i][d[n]-1];
    }
    cout<<sum<<endl;
    return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
