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;
bool isSubsequence (vector < int > v);
bool ask (int bg, int pf, int sf)
{
vector < int > curr;
while (pf --)
curr.push_back (bg);
bg ^= 1;
while (sf --)
curr.push_back (bg);
return isSubsequence (curr);
}
vector < int > findSequence (int N)
{
int lim = N / 2 + 1, K = -1, leastFrequent = -1;///we want to fit this limit and we will
int s[5000];
for (int minL = 0; minL <= N / 2; minL ++)
{
if (ask (0, minL + 1, 0) == 0)
{
K = minL;
leastFrequent = 0;
break;
}
if (ask (1, minL + 1, 0) == 0)
{
K = minL;
leastFrequent = 1;
break;
}
}
assert (K != -1 && leastFrequent != -1);
s[K + 1] = N - K, s[0] = 0;
for (int i=1; i<=K; i++)
{
s[i] = s[i - 1];
bool q = 1;
while (s[i] + K + 1 - i <= lim)
{
q = ask (leastFrequent ^ 1, s[i], K + 1 - i);
if (q == 0)
{
s[i] --;
break;
}
s[i] ++;
}
if (q == 0) continue;///found it without reversing
int opS = 0;
while (opS + i <= lim)
{
q = ask (leastFrequent, i, opS);
if (q == 0)
{
opS --;
break;
}
opS ++;
}
if (q == 0) s[i] = N - K - opS;
else opS --, s[i] = N - K - opS;///in this case I'm right at half of it, and couldn't afford asking one more query
///the answer to that query, however, should've been negative anyways, so there's no problem actually
}
for (int i=K + 1; i>=1; i--)
s[i] -= s[i - 1];
vector < int > ans;
for (int i=1; i<=K + 1; i++)
{
while (s[i] --)
ans.push_back (leastFrequent ^ 1);
if (i != K + 1) ans.push_back (leastFrequent);
}
return ans;
}
Compilation message (stderr)
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++)
~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |