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 "Anna.h"
#include <bits/stdc++.h>
using namespace std;
int Declare()
{
return 2000;
}
namespace
{
long long count(int N)
{
long long R = 0;
for (int K = 0; (2 << K) - 2 <= N; K++)
R = max(R, (long long)(2 * (N - ((2 << K) - 2)) + 1) << (2 * K));
return R;
}
int findK(int N)
{
long long R = 0;
int ak = 0;
for (int K = 0; (2 << K) - 2 <= N; K++)
{
long long v = (long long)(2 * (N - ((2 << K) - 2)) + 1) << (2 * K);
if (R < v)
R = v, ak = K;
}
return ak;
}
pair<vector<int>, vector<int>> solve(int N, long long A)
{
vector<int> L(N), R(N);
int K = findK(N);
for (int i = 0; i < K; i++)
{
fill(L.begin() + (1 << i) - 1, L.begin() + (2 << i) - 1, A & 1);
fill(R.begin() + (1 << i) - 1, R.begin() + (2 << i) - 1, A & 1);
A >>= 1;
fill(L.end() - ((2 << i) - 1), L.end() - ((1 << i) - 1), A & 1);
fill(R.end() - ((2 << i) - 1), R.end() - ((1 << i) - 1), A & 1);
A >>= 1;
}
for (int i = 0; i < A; i++)
if (i & 1)
R[(1 << K) - 1 + i / 2] = 1;
else
L[(1 << K) - 1 + i / 2] = 1;
return {L, R};
}
}
pair<vector<int>, vector<int>> Anna(long long A)
{
--A;
for (int i = 1; i <= 2000; i++)
{
long long K = count(i);
if (A >= K)
A -= K;
else
return solve(i, A);
}
assert(false);
}
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;
namespace
{
long long count(int N)
{
long long R = 0;
for (int K = 0; (2 << K) - 2 <= N; K++)
R = max(R, (long long)(2 * (N - ((2 << K) - 2)) + 1) << (2 * K));
return R;
}
int findK(int N)
{
long long R = 0;
int ak = 0;
for (int K = 0; (2 << K) - 2 <= N; K++)
{
long long v = (long long)(2 * (N - ((2 << K) - 2)) + 1) << (2 * K);
if (R < v)
R = v, ak = K;
}
return ak;
}
long long solve(vector<int> u)
{
int N = u.size() / 2;
int k = findK(N);
long long x = count(u.begin(), u.end(), 1);
long long bs = 0;
int deg = 0;
for(int i=0; i<k; i++)
{
long long L = u[(2<<i)-2], R = u[(2*N-1)-((2<<i)-2)];
bs += L << (deg++);
bs += R << (deg++);
x -= L << (i+1);
x -= R << (i+1);
}
return (x << deg) + bs;
}
}
long long Bruno(vector<int> u)
{
long long ans = 1;
for (int i = 1; i < (int)u.size() / 2; i++)
ans += count(i);
return ans + solve(u);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |