# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
433519 | Lam_lai_cuoc_doi | Hidden Sequence (info1cup18_hidden) | C++17 | 0 ms | 0 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;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
constexpr bool typetest = 0;
constexpr int N = 2e2 + 2;
bool Check(int a, int b, int c)
{
vector<int> ans(a, c);
while (b--)
ans.emplace_back(c ^ 1);
return isSubsequence(ans);
}
vector<int> findSequence(int n)
{
vector<int> ans;
int total(0); // number of zero
// count number of zero
for (int i = 1; i <= n / 2 + 1; ++i)
{
if (!Check(i, 0, 0))
break;
total = i;
}
if (total == n / 2 + 1)
{
total = 0;
for (int i = 1; i <= n / 2 + 1; ++i)
{
if (!Check(i, 0, 1))
break;
total = i;
}
total = n - total;
}
// Cal ans
/* Let i is the bit 0 now we're considering (It means there are i - 1 filled - bits)
j is the bit 1 now we're considering (It means there are j - 1 filled - bits)
There are 2 cases:
- if j + (total - i + 1) <= n / 2, we could check string (j * '1' + (total - i + 1) * '0') because the bit 0 before we don't need to care
- if j + (total - i + 1) > n / 2 <-> n - j - total + i - 1 < n / 2 <-> i + (n - j - total) <= n / 2:
we could checkstring (i * '0' + (n - j - total) * '1')
because the string before the (i - 1) - 0 bit is defined so it's only necessary to check string after i - 0 bit
*/
for (int i = 1, j = 0; i <= total; ++i) // the bit 0 now we're considering
{
for (; j <= n - total; ++j)
{
if (j + (total - i + 1) ? !Check(j, total - i + 1, 1) : Check(i, n - total - j, 0))
break;
ans.emplace_back(1);
}
ans.emplace_back(0);
}
while (ans.size() < n)
ans.emplace_back(1);
return ans;
}