Submission #946296

# Submission time Handle Problem Language Result Execution time Memory
946296 2024-03-14T13:27:11 Z Zena_Hossam Beautiful row (IZhO12_beauty) C++14
100 / 100
1420 ms 205732 KB
#include <bits/stdc++.h>
using namespace std;
#define fi ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//#define ll double
#define ll long long
//#define ll1 int
#define F first
#define S second
#define sz size()
#define all(s) s.begin(),s.end()
#define all1(s) s.rbegin(),s.rend()
ll c=0,n;vector<vector<ll>>s;
ll r[(1<<20)+5][25];
ll solve(ll uu,ll k,ll o){
    ll u=uu;u=(u|(1<<k));
    if(r[uu][k]!=-1)return r[uu][k];r[uu][k]=0;
    //cout<<k<<" ";
if(__builtin_popcount(u)==n){
   return r[uu][k]=1;

}ll x=0;
for(ll i=0;i<s[k].sz;i++){

    if((u&(1<<(s[k][i]))))continue;
    x+=solve(u,s[k][i],o+1);
}return r[uu][k]=x;
}
int main()
{
    //freopen("stdin.in","r",stdin);freopen("stdout.out","w",stdout);
    ll T=1;fi
    //cin>>T;ll oo=0;
    while(T--)
    {for(ll i=0;i<(1<<20)+5;i++){
    for(ll j=0;j<=20;j++)r[i][j]=-1;
    }
       cin>>n;
       ll arr[n];s.resize(n+5);
       for(ll i=0;i<n;i++){
        cin>>arr[i];
       }ll m[n+5]={};ll d[n+5]={};
       for(ll i=0;i<n;i++){
            ll a=arr[i];ll p=0;
            while(a!=0){
                if(a%2==1)p++;
                a/=2;
            }
            m[i]=p;
            ll b=arr[i];ll pp=0;
            while(b!=0){
                if(b%3==1)pp++;
                b/=3;
            }
            d[i]=pp;
       }
       for(ll i=0;i<n;i++){
        for(ll j=i+1;j<n;j++){if(i==j)continue;
            if(m[i]==m[j]){s[i].push_back(j);//cout<<i<<" "<<j<<"k\n";
            s[j].push_back(i);}
            else if(d[i]==d[j]){s[i].push_back(j);//cout<<i<<" "<<j<<"k\n";
            s[j].push_back(i); }
        }
       }ll c=0;
       for(ll i=0;i<n;i++){
       c+=solve(0,i,0);//cout<<"\n";
       }cout<<c;
    }
}

Compilation message

beauty.cpp: In function 'long long int solve(long long int, long long int, long long int)':
beauty.cpp:16:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   16 |     if(r[uu][k]!=-1)return r[uu][k];r[uu][k]=0;
      |     ^~
beauty.cpp:16:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   16 |     if(r[uu][k]!=-1)return r[uu][k];r[uu][k]=0;
      |                                     ^
beauty.cpp:22:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 | for(ll i=0;i<s[k].sz;i++){
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 28 ms 205392 KB Output is correct
2 Correct 30 ms 205652 KB Output is correct
3 Correct 28 ms 205508 KB Output is correct
4 Correct 26 ms 205400 KB Output is correct
5 Correct 27 ms 205396 KB Output is correct
6 Correct 26 ms 205660 KB Output is correct
7 Correct 26 ms 205480 KB Output is correct
8 Correct 27 ms 205508 KB Output is correct
9 Correct 29 ms 205392 KB Output is correct
10 Correct 27 ms 205404 KB Output is correct
11 Correct 34 ms 205548 KB Output is correct
12 Correct 33 ms 205480 KB Output is correct
13 Correct 69 ms 205404 KB Output is correct
14 Correct 257 ms 205632 KB Output is correct
15 Correct 314 ms 205732 KB Output is correct
16 Correct 208 ms 205628 KB Output is correct
17 Correct 297 ms 205628 KB Output is correct
18 Correct 167 ms 205636 KB Output is correct
19 Correct 1376 ms 205632 KB Output is correct
20 Correct 1420 ms 205636 KB Output is correct