# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
716443 | vjudge1 | Beautiful row (IZhO12_beauty) | C++17 | 836 ms | 146436 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>
#define f first
#define s second
#define ent '\n'
#define int long long
#pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
//typedef long double ld;
typedef long long ll;
using namespace std;
struct node{double x,y;};
//double len(node a,node b)
//{return sqrt((a.x-b.x)*(a.x-b.y)+(a.y-b.y)*(a.x-b.y));}
struct seg{
int mx1=0,mx2=0,ans=0;
};
const string out[2]={"NO\n","YES\n"};
const ll dx[]={0,0,1,-1,-1,1,1,-1};
const ll dy[]={1,-1,0,0,-1,1,-1,1};
const int md=998244353;
const int mod=1e9+7;
const int mx=8e5+12;
const int tst=1e5;
const bool T=0;
vector<int> g[mx];
int dp[22][1<<21];
int q[mx];
int a[mx];
int n,m,k;
void Press_Fn_with_F11(){
cin>>n;
for(int i=1;i<=n;i++)cin>>q[i];
sort(q+1,q+n+1);
for(int i=1;i<=n;i++){
int a=0,b=0,x=q[i];
while(x){
a+=x%2;
x/=2;
}
x=q[i];
while(x){
b+=(x%3==1);
x/=3;
}
for(int j=1;j<=n;j++){
if(i==j)continue;
int c=0,d=0,x=q[j];
while(x){
c+=x%2;
x/=2;
}
x=q[j];
while(x){
d+=(x%3==1);
x/=3;
}
if(a==c || b==d)g[i].push_back(j);
}
dp[i][(1ll<<(i-1))]=1;
}
for(int i=1;i<(1ll<<n);i++){
for(int j=1;j<=n;j++){
if(!(i&(1ll<<(j-1))))continue;
for(int x:g[j]){
if((i&(1ll<<(x-1))))continue;
dp[x][i+(1ll<<(x-1))]+=dp[j][i];
}
}
}
int ans=0;
for(int i=1;i<=n;i++)ans+=dp[i][(1ll<<n)-1];
cout<<ans<<ent;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int Ersayin_abi_crush=1;
if(T)cin>>Ersayin_abi_crush;
for(int i=1;i<=Ersayin_abi_crush;i++){
// cout<<"Case "<<i<<": ";
Press_Fn_with_F11();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |