답안 #44826

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
44826 2018-04-07T10:45:50 Z aome Hidden Sequence (info1cup18_hidden) C++17
100 / 100
148 ms 584 KB
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;

int n, f[205];

void solve(int t, vector<int> &res) {
	int len = 0;
	vector<int> ask;
	for (int i = 1; i <= n / 2; ++i) {
		ask.assign(i, t);
		if (isSubsequence(ask)) len = i;
	}

	// suppose 0s < 1s
	f[len] = n - len;

	for (int i = 0; i < len; ++i) {
		int a = i, b = len - 1 - i;
		// a number of 0s to the left
		// b number of 0s to the right


		int c = 0, d = 0;
		// c number of 1s to the left
		// d number of 1s to the right 

		// cout << "#at " << i << '\n';
	
		while (a + d <= n / 2) {
			ask.clear();
			for (int j = 0; j <= a; ++j) ask.push_back(t);
			for (int j = 0; j < d; ++j) ask.push_back(t ^ 1);
			if (!isSubsequence(ask)) break;
			d++;
		}

		while (b + c <= n / 2) {
			ask.clear();
			for (int j = 0; j < c; ++j) ask.push_back(t ^ 1);
			for (int j = 0; j <= b; ++j) ask.push_back(t);
			if (!isSubsequence(ask)) break;
			c++;
		}

		c--, d--;

		// cout << c << ' ' << d << '\n';

		if (a + d <= c + b) {
			f[i] = n - len - d;
		}

		else {
			f[i] = c;
		}
	}

	for (int i = len; i >= 1; --i) f[i] -= f[i - 1];

	for (int i = 0; i < len; ++i) {
		for (int j = 0; j < f[i]; ++j) res.push_back(t ^ 1);
		res.push_back(t);
	}
	for (int i = 0; i < f[len]; ++i) res.push_back(t ^ 1);
}

vector<int> findSequence(int _n) {
	n = _n;
   	vector<int> vec, res;
   	vec.assign(n / 2 + 1, 0);
   	if (isSubsequence(vec)) solve(1, res);
   	else solve(0, res);
   	return res;
}

Compilation message

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++)
                   ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct: Maximum length of a query = 5
2 Correct 2 ms 376 KB Output is correct: Maximum length of a query = 6
3 Correct 2 ms 376 KB Output is correct: Maximum length of a query = 5
4 Correct 2 ms 388 KB Output is correct: Maximum length of a query = 5
5 Correct 2 ms 452 KB Output is correct: Maximum length of a query = 4
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 452 KB Output is correct: Maximum length of a query = 83
2 Correct 100 ms 452 KB Output is correct: Maximum length of a query = 90
3 Correct 126 ms 452 KB Output is correct: Maximum length of a query = 96
4 Correct 68 ms 504 KB Output is correct: Maximum length of a query = 77
5 Correct 114 ms 504 KB Output is correct: Maximum length of a query = 95
6 Correct 73 ms 512 KB Output is correct: Maximum length of a query = 87
7 Correct 109 ms 512 KB Output is correct: Maximum length of a query = 97
8 Correct 77 ms 512 KB Output is correct: Maximum length of a query = 83
9 Correct 132 ms 568 KB Output is correct: Maximum length of a query = 101
10 Correct 136 ms 576 KB Output is correct: Maximum length of a query = 100
11 Correct 148 ms 576 KB Output is correct: Maximum length of a query = 96
12 Correct 73 ms 580 KB Output is correct: Maximum length of a query = 100
13 Correct 127 ms 584 KB Output is correct: Maximum length of a query = 101