# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
760183 | Unforgettablepl | 아름다운 순열 (IZhO12_beauty) | C++17 | 507 ms | 205548 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.
/*
ID: samikgo1
TASK:
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<ll,ll> pll;
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define f first
#define s second
//#define x first
//#define y second
const int INF = INT32_MAX;
const ll modulo = 1e4;
//#define int ll
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("input.in","r",stdin);
// freopen("haybales.out","w",stdout);
ll n;
cin >> n;
vector<pair<ll,ll>> arr(n);
auto countbit = [](ll a){
ll onesa = 0;
ll backa = a;
while(a){
if(a%3==1)onesa++;
a/=3;
}
return make_pair(bitset<32>(backa).count(),onesa);
};
for(pair<ll,ll>&a:arr){cin>>a.first;a=countbit(a.first);}
vector<vector<ll>> DP(1<<n,vector<ll>(n));
for (ll i = 0; i < n; i++)DP[1<<i][i]=1;
for (ll subset = 2; subset < 1<<n; subset++) {
for (ll end = 0; end < n; end++) {
if(!(subset&(1<<end)))continue; //If end doesnt exist in subset there cant be a possible array ending with it
ll previous = subset-(1<<end);
for (ll i = 0; i < n; i++) {
// Ending of previous array
if(arr[end].first!=arr[i].first and arr[end].second!=arr[i].second)continue; // Not compatible
DP[subset][end]+=DP[previous][i];
}
}
}
ll ans = 0;
for(ll&i:DP[(1<<n)-1])ans+=i;
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |