Submission #47212

# Submission time Handle Problem Language Result Execution time Memory
47212 2018-04-29T06:45:30 Z Kmcode Hidden Sequence (info1cup18_hidden) C++14
95 / 100
8 ms 624 KB
#include "bits/stdc++.h"
#include "grader.h"
using namespace std;

static int dp[202];
static 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;
	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) {
		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()==0){
	return zero;
}
if(zero.size()==0){
	return one;
}
	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: In function 'std::vector<int> ask(std::vector<std::pair<int, int> >, std::vector<int>)':
hidden.cpp:9:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i <= v1.size(); i++) {
                  ~~^~~~~~~~~~~~
hidden.cpp:14:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < v1.size(); i++) {
                  ~~^~~~~~~~~~~
hidden.cpp: In function 'std::vector<int> calc(std::vector<int>, int, int, int)':
hidden.cpp:73:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < ar.size(); i++) {
                   ~~^~~~~~~~~~~
hidden.cpp:125:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < ar.size(); i++) {
                  ~~^~~~~~~~~~~
hidden.cpp: In function 'std::vector<int> findSequence(int)':
hidden.cpp:148:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while (zero.size() + one.size() < 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++)
                   ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct: Maximum length of a query = 5
2 Partially correct 2 ms 448 KB Output is partially correct: Maximum length of a query = 8
3 Correct 2 ms 448 KB Output is correct: Maximum length of a query = 5
4 Correct 2 ms 448 KB Output is correct: Maximum length of a query = 5
5 Partially correct 3 ms 448 KB Output is partially correct: Maximum length of a query = 5
# Verdict Execution time Memory Grader output
1 Correct 6 ms 576 KB Output is correct: Maximum length of a query = 83
2 Correct 7 ms 576 KB Output is correct: Maximum length of a query = 90
3 Correct 8 ms 576 KB Output is correct: Maximum length of a query = 96
4 Correct 5 ms 624 KB Output is correct: Maximum length of a query = 77
5 Correct 6 ms 624 KB Output is correct: Maximum length of a query = 95
6 Correct 5 ms 624 KB Output is correct: Maximum length of a query = 87
7 Correct 5 ms 624 KB Output is correct: Maximum length of a query = 97
8 Correct 6 ms 624 KB Output is correct: Maximum length of a query = 83
9 Correct 7 ms 624 KB Output is correct: Maximum length of a query = 101
10 Correct 7 ms 624 KB Output is correct: Maximum length of a query = 100
11 Correct 6 ms 624 KB Output is correct: Maximum length of a query = 96
12 Correct 7 ms 624 KB Output is correct: Maximum length of a query = 100
13 Correct 8 ms 624 KB Output is correct: Maximum length of a query = 101