# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90116 | YottaByte | Beautiful row (IZhO12_beauty) | C++14 | 3035 ms | 684 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 <vector>
using namespace std;
#define pb push_back
const int N = 20;
vector < int > a;
int n, ans;
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)
{
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 bt(vector < int > b, vector < int > u)
{
if(b.size() == n)
{
if(check(b)) ans++;
return;
}
for(int i = 0; i < n; i++)
{
if(!u[i])
{
b.pb(a[i]);
u[i] = 1;
bt(b, u);
b.pop_back();
u[i] = 0;
}
}
}
void out()
{
for(int i = 1; i <= n; i++)
{
cout << a[i] << " ";
}
}
main()
{
cin >> n;
for(int i = 0; i < n; i++)
{
int x; cin >> x;
a.pb(x);
}
vector < int > u, e;
for(int i = 0; i < n; i++)
u.pb(0);
e.clear();
bt( e, u );
cout << ans << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |