Submission #1121442

#TimeUsernameProblemLanguageResultExecution timeMemory
1121442ezzzayBeautiful row (IZhO12_beauty)C++14
0 / 100
3051 ms504 KiB
#include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back const int N=3e5+5; int a[N]; int bincnt(int n){ int p=0; while(n>0){ p+=n%2; n/=2; } return p; } int tercnt(int n){ int p=0; while(n>0){ if(n%3==1)p++; n/=3; } return p; } int bc[N],tc[N]; signed main(){ int ans=0; int n; cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; bc[i]=bincnt(a[i]); tc[i]=tercnt(a[i]); // cout<<bc[i]<<" "<<tc[i]<<endl; } vector<int>vec; for(int i=1;i<=n;i++)vec.pb(i); do{ bool u=1; for(int i=1;i<n;i++){ int x=vec[i],y=vec[i-1]; if(bc[x]!=bc[y] and tc[x]!=tc[y] )u=0; } ans+=u; }while(next_permutation(vec.begin(),vec.end())); cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...