Submission #45020

# Submission time Handle Problem Language Result Execution time Memory
45020 2018-04-10T16:41:26 Z zadrga Hidden Sequence (info1cup18_hidden) C++14
Compilation error
0 ms 0 KB
#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;
}

Compilation message

hidden.cpp: In function 'bool ask(int, int, int)':
hidden.cpp:30:9: error: 'isSequence' was not declared in this scope
  return isSequence(q);
         ^~~~~~~~~~
hidden.cpp:30:9: note: suggested alternative: 'findSequence'
  return isSequence(q);
         ^~~~~~~~~~
         findSequence
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++)
                   ~^~~~~~~~~~~~