Submission #674310

# Submission time Handle Problem Language Result Execution time Memory
674310 2022-12-23T16:58:54 Z QwertyPi Hidden Sequence (info1cup18_hidden) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int, int>

#define TEST

#ifndef TEST
#include "grader.h"
#endif

using namespace std;

vector<int> a;
#ifdef TEST
bool isSubsequence(vector<int> S){
	// cout << "QRY "; for(auto i : S) cout << i << ' '; 
	int l = 0, r = 0;
	while(l < a.size() && r < S.size()){
		if(a[l] != S[r]) l++;
		else l++, r++;
	}
	// cout << (r == S.size() ? "YES" : "NO") << endl;
	return r == S.size();
}
#else
bool isSubsequence(vector<int> S);
#endif

bool flipped = false;
bool iss(vector<int> S){
	if(flipped) for(auto& i : S) i = 1 - i;
	return isSubsequence(S);
}

int dp[201][201];
vector<int> findSequence(int N){
	int c0 = 0, c1 = 0;
	for(int i = 1; i <= N / 2 + 1; i++){
		vector<int> a; for(int j = 0; j < i; j++) a.push_back(0);
		if(!isSubsequence(a)){
			c0 = i - 1, c1 = N - (i - 1);
			break;
		}
	}
	for(int i = 1; i <= N / 2 + 1; i++){
		vector<int> a; for(int j = 0; j < i; j++) a.push_back(1);
		if(!isSubsequence(a)){
			c0 = N - (i - 1), c1 = i - 1;
			break;
		}
	}
	if(c0 >= c1) flipped = true, swap(c0, c1);

	for(int l = 0; l <= c0; l++){
		for(int r = 0; r <= c0; r++){
			if(l - 1 != r) dp[l][r] = -1;
		}
	}
	for(int l = 0; l <= c0; l++){
		for(int r = l; r <= c0; r++){
			int d = r - l;
			int quota = (N / 2 + 1) - (c0 - d);
			for(int k = 1; k <= quota; k++){
				vector<int> qry;
				for(int j = 0; j < l; j++){
					qry.push_back(0);
				}
				for(int j = 1; j <= k; j++){
					qry.push_back(1);
				}
				for(int j = r; j < c0; j++){
					qry.push_back(0);
				}
				if(!iss(qry)) {
					dp[l][r] = k - 1;
					break;
				}
			}
		}
	}

	dp[0][c0] = c1;
	for(int tr = 0; tr <= c0; tr++){
		for(int i = 0; i < c0; i++){
			for(int j = i; j < c0; j++){
				if(dp[i][j] == -1 && dp[i + 1][j] != -1 && dp[i][j + 1] != -1 && dp[i + 1][j + 1] != -1)
					dp[i][j] = dp[i + 1][j] + dp[i][j + 1] - dp[i + 1][j + 1];
				
				if(dp[i][j] != -1 && dp[i + 1][j] == -1 && dp[i][j + 1] != -1 && dp[i + 1][j + 1] != -1)
					dp[i + 1][j] = dp[i][j] - dp[i][j + 1] + dp[i + 1][j + 1];
				
				if(dp[i][j] != -1 && dp[i + 1][j] != -1 && dp[i][j + 1] == -1 && dp[i + 1][j + 1] != -1)
					dp[i][j + 1] = dp[i][j] - dp[i + 1][j] + dp[i + 1][j + 1];
				
				if(dp[i][j] != -1 && dp[i + 1][j] != -1 && dp[i][j + 1] != -1 && dp[i + 1][j + 1] == -1)
					dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] - dp[i][j];
				
			}
		}
		for(int i = 0; i <= c0; i++){
			for(int j = 0; j <= c0; j++){
				cout << dp[i][j] << ' ';
			}
			cout << endl;
		}
		cout << endl;
	}
	vector<int> ans;
	int tot = 0;
	for(int i = 0; i <= c0; i++){
		tot += dp[i][i] == -1 ? 0 : dp[i][i];
	}
	
	for(int i = 0; i <= c0; i++){
		if(dp[i][i] == -1){ dp[i][i] = c1 - tot; }
	}
	
	for(int i = 0; i <= c0; i++){
		for(int j = 0; j < dp[i][i]; j++) ans.push_back(1);
		if(i != c0) ans.push_back(0);
	}
	
	if(flipped){
		for(auto& i : ans) i = 1 - i;
	}
	return ans;
}

#ifdef TEST
int32_t main(){
	int n; cin >> n;
	vector<int> a;
	for(int i = 0; i < n; i++){
		int v; cin >> v; a.push_back(v);
	}
	::a = a;
	vector<int> ans = findSequence(n);
	for(auto i : ans) cout << i << ' '; cout << endl;
}
#endif

Compilation message

hidden.cpp: In function 'bool isSubsequence(std::vector<long long int>)':
hidden.cpp:20:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  while(l < a.size() && r < S.size()){
      |        ~~^~~~~~~~~~
hidden.cpp:20:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  while(l < a.size() && r < S.size()){
      |                        ~~^~~~~~~~~~
hidden.cpp:25:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  return r == S.size();
      |         ~~^~~~~~~~~~~
hidden.cpp: In function 'int32_t main()':
hidden.cpp:140:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  140 |  for(auto i : ans) cout << i << ' '; cout << endl;
      |  ^~~
hidden.cpp:140:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  140 |  for(auto i : ans) cout << i << ' '; cout << endl;
      |                                      ^~~~
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++)
      |                   ~^~~~~~~~~~~~
/usr/bin/ld: /tmp/ccIlAXzt.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccRprxZv.o:hidden.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccIlAXzt.o: in function `main':
grader.cpp:(.text.startup+0x4a): undefined reference to `findSequence(int)'
collect2: error: ld returned 1 exit status