# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
867653 | sleepntsheep | Beautiful row (IZhO12_beauty) | C++17 | 521 ms | 164492 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 <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
using namespace std;
#define ALL(x) x.begin(), x.end()
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
using ll = long long;
#define N 20
int n, a[N], b3[N], d[N][N];
ll ans, dp[1<<N][N];
inline int beautiful(int i, int j) { return (__builtin_popcount(a[i]) == __builtin_popcount(a[j])) || b3[i] == b3[j]; }
int main()
{
ShinLena;
cin >> n;
for (int i = 0; i < n; ++i)
{
cin >> a[i];
for (int x = a[i]; x; b3[i] += (x % 3) == 1, x /= 3);
dp[0][i] = 1;
}
for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) d[i][j] = beautiful(i, j);
for (int k = 0; k < (1 << n); ++k)
{
for (int j = 0; j < n; ++j)
{
if (!(k&(1<<j))) continue;
for (int l = 0; l < n; ++l)
{
if (k & (1 << l))
dp[k][j] += d[j][l] * dp[k&~(1<<j)][l];
}
}
}
for (int i = 0; i < n; ++i) ans += dp[(1<<n)-1][i];
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |