# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
45020 | zadrga | Hidden Sequence (info1cup18_hidden) | C++14 | 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>
#include "grader.h"
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 3111
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
int pre[maxn];
bool ask(int cur, int lf, int rg){
vector<int> q;
while(lf--)
q.pb(cur);
cur ^= 1;
while(rg--)
q.pb(cur);
return isSequence(q);
}
vector<int> findSequence(int N){
int lim = N / 2 + 1, K = -1, less = -1;
for(int i = 0; i <= N / 2; i++){
if(ask(0, i + 1, 0) == 0){
K = i;
less = 0;
break;
}
if(ask(1, i + 1, 0) == 0){
K = i;
less = 1;
break;
}
}
pre[0] = 0;
pre[K + 1] = N - K;
for(int i = 1; i <= K; i++){
pre[i] = pre[i - 1];
bool q = 1;
while(pre[i] + K + 1 - i <= lim){
q = ask(less ^ 1, pre[i], K + 1 - i);
if(q == 0){
pre[i]--;
break;
}
pre[i]++;
}
if(q == 0)
continue;
int rev = 0;
while(i + rev <= lim){
q = ask(less, i, rev);
if(q == 0){
rev--;
break;
}
rev++;
}
if(q == 0)
pre[i] = N - K - rev;
else{
rev--; //in this case I'm right at half of it, and couldn't afford asking one more query
pre[i] = N - K - rev; //the answer to that query, however, should've been negative anyways, so there'pre no problem actually
}
}
for(int i = K + 1; i >= 1; i--)
pre[i] -= pre[i - 1];
vector<int> ans;
for(int i = 0; i <= K + 1; i++){
while(pre[i]--)
ans.pb(less ^ 1);
if(i != K + 1)
ans.pb(less);
}
return ans;
}