# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
701985 | Darren0724 | Beautiful row (IZhO12_beauty) | C++17 | 1500 ms | 172748 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 all(x) x.begin(),x.end()
#define int long long
signed 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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |