int dp[202];
int pr[202];
vector<int> ask(vector<pair<int, int> > v1, vector<int> fin) {
for (int i = 0; i <= v1.size(); i++) {
dp[i] = INT_MAX;
pr[i] = -1;
}
dp[0] = 0;
dp[1] = 0;
for (int i = 0; i < v1.size(); i++) {
if (fin[i]) {
dp[i + 2] = min(dp[i + 2], dp[i] + v1[i].second);
if (dp[i + 2] == dp[i] + v1[i].second) {
pr[i + 2] = 2;
}
}
dp[i + 1] = min(dp[i + 1], dp[i] + 1);
if (dp[i + 1] == dp[i] + 1) {
pr[i + 1] = 1;
}
}
vector<int> ret;
int cur = v1.size();
while (cur>1) {
if (pr[cur] == 1) {
ret.push_back(v1[cur - 1].first);
}
else {
while (v1[cur - 2].second--) {
ret.push_back(v1[cur - 2].first);
}
}
cur -= pr[cur];
}
reverse(ret.begin(), ret.end());
return ret;
}
vector<int> calc(vector<int> v, int add, int lim, int n) {
int z = 0;
vector<pair<int, int> > ar; //kind len
vector<bool> fin;
int rest_add = n - v.size();
for (int i = v.size(); i>=0; i--) {
vector<int> tmp=v;
tmp.insert(tmp.begin() + v.size() - i, add);
if (isSubsequence(tmp)) {
if (z) {
ar.push_back(make_pair(add^true, z));
fin.push_back(true);
z = 0;
}
ar.push_back(make_pair(add, 1));
fin.push_back(false);
rest_add--;
if(i!=0)z++;
}
else {
if(i!=0)z++;
}
}
if (z) {
ar.push_back(make_pair(add ^ true, z));
fin.push_back(true);
}
int idx = 0;
while (rest_add) {
int fc = 0;
int las = 0;
for (int i = 0; i < ar.size(); i++) {
if (fin[i]==false) {
fc++;
las = i;
}
}
if (fc == 1) {
ar[las].second += rest_add;
rest_add = 0;
continue;
}
if (fin[idx] == false) {
vector<int> query;
{
vector<pair<int, int> > v2;
vector<int> f2;
for (int i = 0; i < idx; i++) {
v2.push_back(ar[i]);
f2.push_back(fin[i]);
}
query = ask(v2, f2);
}
int add = ar[idx].second;
add++;
while (add--) {
query.push_back(ar[idx].first);
}
{
vector<pair<int, int> > v2;
vector<int> f2;
for (int i = ar.size()-1; i > idx; i--) {
v2.push_back(ar[i]);
f2.push_back(fin[i]);
}
auto query2 = ask(v2, f2);
reverse(query2.begin(), query2.end());
for (int el : query2) {
query.push_back(el);
}
}
if (isSubsequence(query)) {
rest_add--;
ar[idx].second++;
}
else {
fin[idx] = true;
}
}
idx++;
idx %= ar.size();
}
vector<int> ans;
for (int i = 0; i < ar.size(); i++) {
while (ar[i].second--) {
ans.push_back(ar[i].first);
}
}
return ans;
}
vector<int> findSequence(int N) {
vector<int> zero;
vector<int> one;
for (int i = 0; i < N / 2 + 1; i++) {
zero.push_back(0);
one.push_back(1);
if (isSubsequence(zero)) {
}
else {
zero.pop_back();
}
if (!isSubsequence(one)) {
one.pop_back();
}
}
while (zero.size() + one.size() < N) {
if (zero.size() > one.size()) {
zero.push_back(0);
}
else {
one.push_back(1);
}
}
if (one.size() > zero.size()) {
return calc(zero, 1, ( N) / 2 + 3, N);
}
else {
return calc(one, 0, (N) / 2 + 3, N);
}
}
Compilation message
hidden.cpp:4:1: error: 'vector' does not name a type
vector<int> ask(vector<pair<int, int> > v1, vector<int> fin) {
^~~~~~
hidden.cpp:39:1: error: 'vector' does not name a type
vector<int> calc(vector<int> v, int add, int lim, int n) {
^~~~~~
hidden.cpp:129:1: error: 'vector' does not name a type
vector<int> findSequence(int N) {
^~~~~~
grader.cpp: In function 'int main()':
grader.cpp:28:43: warning: format '%d' expects argument of type 'int', but argument 3 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
fprintf (fifo_out, "%d\n", ans.size ());
~~~~~~~~~~~^
grader.cpp:29:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<ans.size () && i < N; i++)
~^~~~~~~~~~~~