# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
328816 | gustason | 아름다운 순열 (IZhO12_beauty) | C++14 | 1 ms | 364 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
pair<int, int> ones[21];
int n;
int ternary_ones(int x) {
int s = 0;
while(x > 0) {
if (x % 3 == 1)
s++;
x /= 3;
}
return s;
}
ll cnt = 0;
void go(int id, bool used[], pair<int, int> last) {
if (id == n) {
cnt++;
return;
}
for(int i = 0; i < n; i++) {
if (used[i])
continue;
if (ones[i].first == last.first || ones[i].first == last.second ||
ones[i].second == last.first || ones[i].second == last.second) {
used[i] = true;
go(id + 1, used, ones[i]);
used[i] = false;
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for(int i = 0; i < n; i++) {
int x;
cin >> x;
ones[i].first = __builtin_popcount(x);
ones[i].second = ternary_ones(x);
}
// for(int i = 0; i < n; i++) {
// cout << ones[i].first << " " << ones[i].second;
// }
bool used[n];
fill(used, used + n, false);
for(int i = 0; i < n; i++) {
used[i] = true;
go(1, used, ones[i]);
used[i] = false;
}
cout << cnt;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |