Submission #881109

#TimeUsernameProblemLanguageResultExecution timeMemory
881109alexddBeautiful row (IZhO12_beauty)C++17
0 / 100
3048 ms348 KiB
#include<iostream>
#include<algorithm>
using namespace std;
int n;
pair<pair<int,int>,pair<int,int>> a[25];
int calc_cnt2(int x)
{
    int rez=0;
    for(int i=0;i<30;i++)
    {
        if(((1<<i)&x))
            rez++;
    }
    return rez;
}
int calc_cnt3(int x)
{
    int rez=0;
    while(x>0)
    {
        if(x%3==1)
            rez++;
        x/=3;
    }
    return rez;
}
signed main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].second.first;
        a[i].first = {calc_cnt2(a[i].second.first), calc_cnt3(a[i].second.first)};
        a[i].second.second=i;

    }
    sort(a+1,a+1+n);
    long long rez=0;
    do
    {
        rez++;
        for(int i=1;i<n;i++)
        {
            if(a[i].first.first!=a[i+1].first.first && a[i].first.second!=a[i+1].first.second)
            {
                rez--;
                break;
            }
        }
    }while(next_permutation(a+1,a+1+n));
    cout<<rez;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...