Submission #701981

#TimeUsernameProblemLanguageResultExecution timeMemory
701981Darren0724Beautiful row (IZhO12_beauty)C++17
0 / 100
5 ms1236 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(),x.end() int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n;cin>>n; vector<int> v(n); vector<int> a(n),b(n); for(int i=0;i<n;i++){ cin>>v[i]; } for(int i=0;i<n;i++){ int p=v[i]; while(p>0){ if(p%3==1){ a[i]++; } p/=3; } p=v[i]; while(p>0){ if(p%2==1){ b[i]++; } p/=2; } } vector<vector<int>> dp(n,vector<int>(1<<n)); for(int i=0;i<n;i++){ dp[i][1<<i]=1; } for(int i=1;i<(1<<n);i++){ for(int j=0;j<n;j++){ if(i&(1<<j)){ for(int k1=0;k1<n;k1++){ if(a[j]==a[k1]||b[j]==b[k1]){ dp[j][i]+=dp[k1][i-(1<<j)]; } } } } } int ans=0; for(int i=0;i<n;i++){ ans+=dp[i][(1<<n)-1]; } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...