# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1121440 | ezzzay | Beautiful row (IZhO12_beauty) | C++14 | 1 ms | 340 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>
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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |