# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90113 | YottaByte | Beautiful row (IZhO12_beauty) | C++14 | 2 ms | 256 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 <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;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |