# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
516815 | Be_dos | Beautiful row (IZhO12_beauty) | C++17 | 903 ms | 189020 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 <cmath>
#include <cctype>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <unordered_set>
#include <sstream>
#include <cstring>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <random>
#include <cfloat>
#include <chrono>
#include <bitset>
#include <complex>
#include <immintrin.h>
#include <cassert>
int main() {
int32_t n;
std::cin >> n;
int32_t* arr = new int32_t[n];
for(int32_t i = 0; i < n; i++)
std::cin >> arr[i];
bool** graph = new bool*[n];
for(int32_t i = 0; i < n; i++) {
graph[i] = new bool[n];
for(int32_t j = 0; j < n; j++) {
if(i == j)
graph[i][j] = false;
else {
graph[i][j] = __builtin_popcount(arr[i]) == __builtin_popcount(arr[j]);
int32_t ones1 = 0;
int32_t cur = arr[i];
while(cur > 0) {
ones1 += (cur % 3) % 2;
cur /= 3;
}
int32_t ones2 = 0;
cur = arr[j];
while(cur > 0) {
ones2 += (cur % 3) % 2;
cur /= 3;
}
graph[i][j] = graph[i][j] || ones1 == ones2;
}
}
}
int64_t** dp = new int64_t*[1 << n];
for(int32_t i = 1; i < (1 << n); i++) {
dp[i] = new int64_t[n];
for(int32_t j = 0 ;j < n; j++)
dp[i][j] = 0;
if(__builtin_popcount(i) == 1) {
dp[i][31 - __builtin_clz(i)] = 1;
continue;
}
for(int32_t j = 0; j < n; j++)
if(i & (1 << j)) {
for(int32_t k = 0; k < n; k++)
if((i & (1 << k)) > 0 && j != k && graph[j][k])
dp[i][j] += dp[i ^ (1 << j)][k];
}
}
int64_t ans = 0;
for(int32_t i = 0; i < n; i++)
ans += dp[(1 << n) - 1][i];
std::cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |