# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
44826 | aome | Hidden Sequence (info1cup18_hidden) | C++17 | 148 ms | 584 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>
#include "grader.h"
using namespace std;
int n, f[205];
void solve(int t, vector<int> &res) {
int len = 0;
vector<int> ask;
for (int i = 1; i <= n / 2; ++i) {
ask.assign(i, t);
if (isSubsequence(ask)) len = i;
}
// suppose 0s < 1s
f[len] = n - len;
for (int i = 0; i < len; ++i) {
int a = i, b = len - 1 - i;
// a number of 0s to the left
// b number of 0s to the right
int c = 0, d = 0;
// c number of 1s to the left
// d number of 1s to the right
// cout << "#at " << i << '\n';
while (a + d <= n / 2) {
ask.clear();
for (int j = 0; j <= a; ++j) ask.push_back(t);
for (int j = 0; j < d; ++j) ask.push_back(t ^ 1);
if (!isSubsequence(ask)) break;
d++;
}
while (b + c <= n / 2) {
ask.clear();
for (int j = 0; j < c; ++j) ask.push_back(t ^ 1);
for (int j = 0; j <= b; ++j) ask.push_back(t);
if (!isSubsequence(ask)) break;
c++;
}
c--, d--;
// cout << c << ' ' << d << '\n';
if (a + d <= c + b) {
f[i] = n - len - d;
}
else {
f[i] = c;
}
}
for (int i = len; i >= 1; --i) f[i] -= f[i - 1];
for (int i = 0; i < len; ++i) {
for (int j = 0; j < f[i]; ++j) res.push_back(t ^ 1);
res.push_back(t);
}
for (int i = 0; i < f[len]; ++i) res.push_back(t ^ 1);
}
vector<int> findSequence(int _n) {
n = _n;
vector<int> vec, res;
vec.assign(n / 2 + 1, 0);
if (isSubsequence(vec)) solve(1, res);
else solve(0, res);
return res;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |