Submission #1121440

#TimeUsernameProblemLanguageResultExecution timeMemory
1121440ezzzayBeautiful row (IZhO12_beauty)C++14
0 / 100
1 ms340 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[a[i]]=bincnt(a[i]); tc[a[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=a[vec[i]],y=a[vec[i-1]]; if(bc[x]!=bc[y] and tc[x]!=tc[y] and bc[x]!=tc[y] and tc[x]!=bc[y])u=0; } ans+=u; }while(next_permutation(vec.begin(),vec.end())); cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...