# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
946271 | Zena_Hossam | Beautiful row (IZhO12_beauty) | C++14 | 1 ms | 1116 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 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 j=25;
ll m[1000][25],vis[1000][25];
ll solve(ll uu,ll k,ll o){
ll u=uu;u=(u|(1<<k));
if(vis[uu][k])return m[uu][k];vis[uu][k]=1;
//cout<<k<<" ";
if(__builtin_popcount(u)==n){
return m[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 m[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--)
{
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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |