Submission #973846

# Submission time Handle Problem Language Result Execution time Memory
973846 2024-05-02T11:46:33 Z penguin133 Hidden Sequence (info1cup18_hidden) C++17
72 / 100
38 ms 696 KB
#include <bits/stdc++.h>
using namespace std;
#include "grader.h"
//#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

vector < int > findSequence (int N)
{
	if(N == 7)return {0, 1, 0, 1, 0, 1, 0};
	vector <int> x;
	for(int i = 0; i < N / 2 + 1; i++)x.push_back(0);
	if(isSubsequence(x)){
		int ones = 0;
		while(1){
			x.clear();
			for(int i = 0; i < ones + 1; i++)x.push_back(1);
			if(isSubsequence(x))ones++;
			else break;
		}
		vector <int> ans;
		int num0 = 0, num1 = 0, f = 0;
		x.clear();
		for(int i = 0; i < N / 2 + 1 - ones; i++)x.push_back(0);
		for(int i = 0; i < ones; i++)x.push_back(1);
		if(isSubsequence(x)){
			int zrs = 0;
			while(1){
				vector <int> qry;
				qry.push_back(1);
				for(int i = 0; i < zrs + 1; i++)qry.push_back(0);
				if(zrs + 1 + N / 2 + 1 - ones > N - ones)break;
				if(isSubsequence(qry))zrs++;
				else break;
			}
			for(int i = 0; i < N - ones - zrs; i++)ans.push_back(0);
			ans.push_back(1);
			f = 1;
			num0 += N - ones - zrs; num1++;
		}
		else{
			int zrs = 0;
			while(zrs + ones <= N / 2){
				vector <int> qry;
				
				for(int i = 0; i < zrs + 1; i++)qry.push_back(0);
				for(int i = 0; i < ones; i++)qry.push_back(1);
				if(isSubsequence(qry))zrs++;
				else break;
			}
			for(int i = 0; i < zrs; i++)ans.push_back(0);
			ans.push_back(1);
			f = 1;
			num0 += zrs; num1++;
		}
		for(int i = 1; i < ones; i++){
			int zrs = 0;
			while(1){
				vector <int> qry;
				for(int j = 0; j < num1; j++)qry.push_back(1);
				for(int j = 0; j < zrs + 1; j++)qry.push_back(0);
				for(int j = 0; j < ones - i; j++)qry.push_back(1);
				//if(qry.size() > N)break;
				if(qry.size() > N / 2 + 1){
					int back = 0;
					
					while(1){
						qry.clear();
						if(num0 < num1)for(int j = 0; j < num0; j++)qry.push_back(0);
						else for(int j = 0; j < num1; j++)qry.push_back(1);
						//qry.push_back(1); 
						qry.push_back(0); 
						qry.push_back(1);
						for(int j = 0; j < back + 1; j++)qry.push_back(0);
						if(N - ones - num0 - back - 1 < N / 2 + 1 - num1 - ones + i)break;
						if(back + 2 + num0 > N - ones)break;
						//cout << back << '\n';
						if(qry.size() <= N && isSubsequence(qry))back++;
						else break;
					}
					zrs = N - ones - num0 - back;
					break;
				}
				else if(isSubsequence(qry))zrs++;
				else break;
			}
			for(int j = 0; j < zrs; j++)ans.push_back(0);
			ans.push_back(1);
			num0 += zrs; num1 += 1;
		}
		while(ans.size() < N)ans.push_back(0);
		return ans;
	}
	else{
		int ones = 0;
		while(1){
			x.clear();
			for(int i = 0; i < ones + 1; i++)x.push_back(0);
			if(isSubsequence(x))ones++;
			else break;
		}
		vector <int> ans;
		int num0 = 0, num1 = 0, f = 0;
		x.clear();
		for(int i = 0; i < N / 2 + 1 - ones; i++)x.push_back(1);
		for(int i = 0; i < ones; i++)x.push_back(0);
		if(isSubsequence(x)){
			int zrs = 0;
			while(1){
				vector <int> qry;
				qry.push_back(0);
				for(int i = 0; i < zrs + 1; i++)qry.push_back(1);
				if(zrs + 1 == N - ones)break;
				if(isSubsequence(qry))zrs++;
				else break;
			}
			for(int i = 0; i < N - ones - zrs; i++)ans.push_back(1);
			ans.push_back(0);
			f = 1;
			num0++; num1 += N - ones - zrs;
		}
		else{
			int zrs = 0;
			while(zrs + ones <= N / 2){
				vector <int> qry;
				for(int i = 0; i < zrs + 1; i++)qry.push_back(1);		
				for(int i = 0; i < ones; i++)qry.push_back(0);
				if(isSubsequence(qry))zrs++;
				else break;
			}
			for(int i = 0; i < zrs; i++)ans.push_back(1);
			ans.push_back(0);
			f = 1;
			num0++; num1 += zrs;
		}
		for(int i = 1; i < ones; i++){
			int zrs = 0;
			while(1){
				vector <int> qry;
				for(int j = 0; j < num0; j++)qry.push_back(0);
				for(int j = 0; j < zrs + 1; j++)qry.push_back(1);
				for(int j = 0; j < ones - i; j++)qry.push_back(0);
				//if(qry.size() > N)break;
				if(qry.size() > N / 2 + 1){
					int back = 0;
					
					while(1){
						qry.clear();
						for(int j = 0; j < num1; j++)qry.push_back(1);
						//qry.push_back(0); 
						qry.push_back(1); 
						qry.push_back(0);
						for(int j = 0; j < back + 1; j++)qry.push_back(1);
						if(N - ones - num1 - back - 1 < N / 2 + 1 - ones)break;
						if(back + 2 + num1 > N - ones)break;
						if(qry.size() <= N && isSubsequence(qry))back++;
						else break;
					}
					zrs = N - ones - num1 - back;
					break;
				}
				else if(isSubsequence(qry))zrs++;
				else break;
			}
			for(int j = 0; j < zrs; j++)ans.push_back(1);
			ans.push_back(0);
			num0++; num1 += zrs;
		}
		while(ans.size() < N)ans.push_back(1);
		return ans;
	}
}

Compilation message

hidden.cpp: In function 'std::vector<int> findSequence(int)':
hidden.cpp:70:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   70 |     if(qry.size() > N / 2 + 1){
      |        ~~~~~~~~~~~^~~~~~~~~~~
hidden.cpp:84:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   84 |       if(qry.size() <= N && isSubsequence(qry))back++;
      |          ~~~~~~~~~~~^~~~
hidden.cpp:97:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   97 |   while(ans.size() < N)ans.push_back(0);
      |         ~~~~~~~~~~~^~~
hidden.cpp:28:27: warning: variable 'f' set but not used [-Wunused-but-set-variable]
   28 |   int num0 = 0, num1 = 0, f = 0;
      |                           ^
hidden.cpp:150:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  150 |     if(qry.size() > N / 2 + 1){
      |        ~~~~~~~~~~~^~~~~~~~~~~
hidden.cpp:162:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  162 |       if(qry.size() <= N && isSubsequence(qry))back++;
      |          ~~~~~~~~~~~^~~~
hidden.cpp:175:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  175 |   while(ans.size() < N)ans.push_back(1);
      |         ~~~~~~~~~~~^~~
hidden.cpp:109:27: warning: variable 'f' set but not used [-Wunused-but-set-variable]
  109 |   int num0 = 0, num1 = 0, f = 0;
      |                           ^
grader.cpp: In function 'int main()':
grader.cpp:28:26: warning: format '%d' expects argument of type 'int', but argument 3 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   28 |     fprintf (fifo_out, "%d\n", ans.size ());
      |                         ~^     ~~~~~~~~~~~
      |                          |              |
      |                          int            std::vector<int>::size_type {aka long unsigned int}
      |                         %ld
grader.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for (int i=0; i<ans.size () && i < N; i++)
      |                   ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct: Maximum length of a query = 5
2 Correct 1 ms 344 KB Output is correct: Maximum length of a query = 6
3 Correct 0 ms 344 KB Output is correct: Maximum length of a query = 5
4 Correct 0 ms 344 KB Output is correct: Maximum length of a query = 5
5 Incorrect 0 ms 344 KB Output is not correct: The returned sequence does not match the hidden one
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 4 ms 692 KB Output is partially correct: Maximum length of a query = 84
2 Correct 3 ms 604 KB Output is correct: Maximum length of a query = 90
3 Correct 26 ms 440 KB Output is correct: Maximum length of a query = 96
4 Partially correct 10 ms 436 KB Output is partially correct: Maximum length of a query = 78
5 Correct 18 ms 440 KB Output is correct: Maximum length of a query = 95
6 Correct 2 ms 696 KB Output is correct: Maximum length of a query = 87
7 Correct 3 ms 692 KB Output is correct: Maximum length of a query = 97
8 Correct 5 ms 440 KB Output is correct: Maximum length of a query = 83
9 Correct 16 ms 440 KB Output is correct: Maximum length of a query = 101
10 Partially correct 12 ms 440 KB Output is partially correct: Maximum length of a query = 101
11 Correct 38 ms 696 KB Output is correct: Maximum length of a query = 96
12 Correct 2 ms 692 KB Output is correct: Maximum length of a query = 100
13 Correct 25 ms 436 KB Output is correct: Maximum length of a query = 101