# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
90113 | YottaByte | 아름다운 순열 (IZhO12_beauty) | C++14 | 2 ms | 256 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 20;
int n, ans;
vector < int > a;
inline bool count(int a, int b)
{
int resa, resb;
resa = resb = 0;
while(a)
{
resa += (a % 3 == 1);
a /= 3;
}
while(b)
{
resb += (b % 3 == 1);
b /= 3;
}
return (resa == resb);
}
inline bool check(vector < int > b)
{
int c = 0;
for(int i = 0; i < n - 1; i++)
{
if(__builtin_popcount(b[i]) == __builtin_popcount(b[i + 1]));
else if(count(b[i], b[i + 1]));
else return false;
}
return true;
}
void out(vector < int > tmp)
{
for(int i = 0; i < tmp.size(); i++)
cout << tmp[i] << " ";
puts("");
}
void bt( vector < int > b, vector < int > u )
{
if(b.size() == n)
{
if(check(b)) ans++;//, out(b);
return;
}
for(int i = 0; i < n; i++)
{
if(!u[i])
{
u[i] = 1;
b.push_back(a[i]);
bt( b, u );
b.pop_back();
u[i] = 0;
}
}
}
main()
{
cin >> n;
for(int i = 0; i < n; i++)
{
int x; cin >> x;
a.push_back(x);
}
sort(a.begin() + 1, a.begin() + 1 + n);
vector < int > t, t1;
t1.clear();
for(int i = 0; i < n; i++)
t.push_back(0);
bt( t1, t );
cout << ans << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |