# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
992520 | tch1cherin | Beautiful row (IZhO12_beauty) | C++17 | 700 ms | 205648 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;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N;
cin >> N;
vector<int> a(N);
for (int &value : a) {
cin >> value;
}
vector<int> b(N), t(N);
for (int i = 0; i < N; i++) {
int tmp = a[i];
while (tmp > 0) {
b[i] += tmp % 2 == 1;
tmp /= 2;
}
tmp = a[i];
while (tmp > 0) {
t[i] += tmp % 3 == 1;
tmp /= 3;
}
}
vector<vector<long long>> dp(1 << N, vector<long long>(N));
for (int i = 0; i < N; i++) {
dp[1 << i][i] = 1;
}
for (int mask = 0; mask < (1 << N); mask++) {
for (int i = 0; i < N; i++) {
if ((mask >> i) & 1) {
for (int j = 0; j < N; j++) {
if ((mask >> j) % 2 == 0 && (b[i] == b[j] || t[i] == t[j])) {
dp[mask | (1 << j)][j] += dp[mask][i];
}
}
}
}
}
long long answer = 0;
for (int i = 0; i < N; i++) {
answer += dp.back()[i];
}
cout << answer << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |