# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1208038 | lopkus | Hidden Sequence (info1cup18_hidden) | C++20 | 3 ms | 424 KiB |
#include<bits/stdc++.h>
#include "grader.h"
using namespace std;
int ask(std::vector<int> r) {
return isSubsequence(r);
}
vector < int > findSequence (int n) {
std::vector<int> t;
for(int i = 1; i <= n / 2 + 1; i++) {
t.push_back(1);
}
if(ask(t)) {
// 0 is smaller
int block = - 1;
std::vector<int> E;
while(ask(E)) {
E.push_back(0);
}
E.pop_back();
std::vector<int> to(n + 1);
for(int i = 0; i <= E.size(); i++) {
std::vector<int> b = E;
while(b.size() < n / 2 + 3) {
b.insert(b.begin() + i, 1);
}
if(ask(b)) {
to[i] = - 69;
continue;
}
b = E;
to[i] = - 1;
while(b.size() < n / 2 + 3 && ask(b)) {
b.insert(b.begin() + i, 1);
to[i] += 1;
}
}
std::vector<int> ans;
int sum = n - E.size();
for(int i = 0; i <= E.size(); i++) {
if(to[i] >= 0) {
sum -= to[i];
}
}
int cnt = 0;
for(int i = 0; i <= E.size(); i++) {
if(to[i] == - 69) {
cnt += 1;
}
}
//assert(sum % cnt == 0);
if(cnt > 0) {
//assert(sum % cnt == 0);
sum /= cnt;
}
for(int i = 0; i <= E.size(); i++) {
if(to[i] == - 69) {
to[i] = sum;
}
}
for(int i = 0; i < to[0]; i++) {
ans.push_back(1);
}
for(int i = 1; i <= E.size(); i++) {
ans.push_back(0);
for(int j = 1; j <= to[i]; j++) {
ans.push_back(1);
}
}
return ans;
}
else {
// 0 is smaller
int block = - 1;
std::vector<int> E;
while(ask(E)) {
E.push_back(1);
}
E.pop_back();
std::vector<int> to(n + 1);
for(int i = 0; i <= E.size(); i++) {
std::vector<int> b = E;
while(b.size() < n / 2 + 3) {
b.insert(b.begin() + i, 0);
}
if(ask(b)) {
to[i] = - 69;
continue;
}
b = E;
to[i] = - 1;
while(b.size() < n / 2 + 3 && ask(b)) {
b.insert(b.begin() + i, 0);
to[i] += 1;
}
}
std::vector<int> ans;
int sum = n - E.size();
for(int i = 0; i <= E.size(); i++) {
if(to[i] >= 0) {
sum -= to[i];
}
}
int cnt = 0;
for(int i = 0; i <= E.size(); i++) {
if(to[i] == - 69) {
cnt += 1;
}
}
//assert(sum % cnt == 0);
if(cnt > 0) {
//assert(sum % cnt == 0);
sum /= cnt;
}
for(int i = 0; i <= E.size(); i++) {
if(to[i] == - 69) {
to[i] = sum;
}
}
for(int i = 0; i < to[0]; i++) {
ans.push_back(0);
}
for(int i = 1; i <= E.size(); i++) {
ans.push_back(1);
for(int j = 1; j <= to[i]; j++) {
ans.push_back(0);
}
}
return ans;
}
}
/**
10
0 1 1 0 0 0 1 1 1 1
**/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |