# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
913823 | cot | Beautiful row (IZhO12_beauty) | C++14 | 3038 ms | 600 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 <algorithm>
#include <map>
#include <array>
#define f first
#define s second
#define pii pair <int, int>
#define pb push_back
using namespace std;
const int N = 50 + 5;
int n, a[N], b[N], p[N], ans, good[N][N];
int ones3(int x) {
int cnt = 0;
while (x > 0) {
if (x % 3 == 1) cnt++;
x /= 3;
}
return cnt;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
p[i] = i;
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (__builtin_popcountll(a[i]) == __builtin_popcountll(a[j]) || ones3(a[i]) == ones3(a[j])) {
good[i][j] = good[j][i] = 1;
continue;
}
}
}
do {
for (int i = 1; i <= n; i++) {
b[i] = a[p[i]];
}
int bad = 0;
for (int i = 1; i < n; i++) {
if (!good[p[i]][p[i + 1]]) bad = 1;
}
if (!bad) ans++;
} while(next_permutation(p + 1, p + n + 1));
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |