Submission #339835

#TimeUsernameProblemLanguageResultExecution timeMemory
339835nandonathanielBeautiful row (IZhO12_beauty)C++14
0 / 100
3063 ms164664 KiB
#include<bits/stdc++.h> using namespace std; const int MAXN=20; #pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") #pragma GCC option("arch=native","tune=native","no-zero-upper") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") int n; long long dp[1<<MAXN][MAXN]; int a[MAXN]; int binary(int x){ return __builtin_popcount(x); } int ternary(int x){ int ret=0; while(x>0){ if(x%3==1)ret++; x/=3; } return ret; } long long DP(int mask,int last){ if(mask==((1<<n)-1))return 1; long long &ret=dp[mask][last]; if(ret!=-1)return ret; ret=0; for(int i=0;i<n;i++){ if(!(mask & (1<<i))){ if(binary(a[last])==binary(a[i]) || ternary(a[last])==ternary(a[i]))ret+=DP(mask+(1<<i),i); } } return ret; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; for(int i=0;i<n;i++)cin >> a[i]; memset(dp,-1,sizeof(dp)); long long ans=0; for(int i=0;i<n;i++)ans+=DP(1<<i,i); cout << ans << '\n'; return 0; }

Compilation message (stderr)

beauty.cpp:5: warning: ignoring #pragma GCC option [-Wunknown-pragmas]
    5 | #pragma GCC option("arch=native","tune=native","no-zero-upper")
      |
#Verdict Execution timeMemoryGrader output
Fetching results...