# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
913823 | cot | Beautiful row (IZhO12_beauty) | C++14 | 3038 ms | 600 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |