# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
312687 | Trickster | Beautiful row (IZhO12_beauty) | C++14 | 955 ms | 246648 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 <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define lm (1<<30)
#define N 30
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mod 1000000007
#define pii pair <ll, ll>
#define sz(a) int(a.size())
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
ll bigmod(ll a,ll e) {if(e==0)return 1;ll x=bigmod(a*a%mod,e>>1);return e&1?x*a%mod:x;}
int n;
ll ans;
pii p[N];
int v[N];
ll dp[(1<<20)][N];
int main()
{
scanf("%d", &n);
for(int i = 0; i < n; i++) {
scanf("%d", &v[i]);
int x = v[i], cnt = 0;
while(x) cnt += x%2, x/=2;
p[i].ff = cnt;
x = v[i], cnt = 0;
while(x) cnt += (x%3 == 1 ? 1 : 0), x/=3;
p[i].ss = cnt;
dp[1<<i][i] = 1;
}
ll ans = 0;
for(int i = 1; i < (1<<n); i++)
for(int h = 0; h < n; h++) {
int b = (1<<h);
if(!(b&i)) continue;
int cur = (1<<h)^(i);
for(int j = 0; j < n; j++) {
b = (1<<j);
if(!(b&cur)) continue;
if(p[h].ff == p[j].ff || p[h].ss == p[j].ss) dp[i][h] += dp[cur][j];
}
if(i == (1<<n)-1) ans += dp[i][h];
}
printf("%lld", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |