# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90109 | YottaByte | Beautiful row (IZhO12_beauty) | C++14 | 303 ms | 704 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 a[N + 1], 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()
{
int c = 0;
for(int i = 1; i < n; i++)
{
if(__builtin_popcount(a[i]) == __builtin_popcount(a[i + 1])) c++;
else if(count(a[i], a[i + 1])) c++;
else return false;
}
return true;
}
void out()
{
for(int i = 1; i <= n; i++)
{
cout << a[i] << " ";
}
}
main()
{
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
sort(a + 1, a + 1 + n);
do
{
if(check())
ans++;
} while(next_permutation(a + 1, a + 1 + n));
cout << ans << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |