Submission #1017923

#TimeUsernameProblemLanguageResultExecution timeMemory
1017923LM1Beautiful row (IZhO12_beauty)C++14
100 / 100
427 ms180864 KiB
#include<bits/stdc++.h>
#define bin __builtin_popcount 
#define ll long long
#define int long long
#define pb push_back
#define ff first
#define ss second
using namespace std;
const int N=22;
int fix[N][N],dp[(1<<N)][N];
int ter(int x){
    int aa=0;
    while(x>0){
    	if(x%3==1)aa++;
        x/=3;
    }
    return aa;
}
main(){
    int n;cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(bin(a[i])==bin(a[j])){
                fix[i][j]=1;
				fix[j][i]=1;
                continue;
            }
            if(ter(a[i])==ter(a[j])){
                fix[i][j]=1;
				fix[j][i]=1;
                continue;
            }
        }
    }
    int ans=0;
    for(int i=1;i<(1<<n);i++){
        vector<int>v;
        for(int j=0;j<n;j++)if((1<<j)&i)v.pb(j);
        if(bin(i)==1){
			dp[i][v[0]]=1;
			continue;
		}
        for(int j=0;j<v.size();j++){
			int l=v[j];
            for(int k=0;k<v.size();k++){
				int l1=v[k];
                if(j==k)continue;
                if(fix[l][l1])dp[i][l]+=dp[i^(1<<l)][l1];
            }
            if(i==(1<<n)-1)ans+=dp[i][l];
        }
    }
    cout<<ans;
}

Compilation message (stderr)

beauty.cpp:19:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   19 | main(){
      | ^~~~
beauty.cpp: In function 'int main()':
beauty.cpp:45:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for(int j=0;j<v.size();j++){
      |                     ~^~~~~~~~~
beauty.cpp:47:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |             for(int k=0;k<v.size();k++){
      |                         ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...