Submission #317201

# Submission time Handle Problem Language Result Execution time Memory
317201 2020-10-29T05:32:14 Z Kevin_Zhang_TW Hidden Sequence (info1cup18_hidden) C++17
59 / 100
112 ms 504 KB
#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] : ", args)
void kout() { cerr << endl; }
template<class T, class ...U>
void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
void debug(auto L, auto R) { while (L != R) cerr << *L << " \n"[next(L) == R], ++L; }
vector<int> ans{0,0,0,0,0,1,0,0,1,1,0};
int mxq;
bool isSubsequence(vector<int> a) {
	for (int i = 0, j = 0;i < a.size();++i) {
		while (j < ans.size() && ans[j] != a[i])
			++j;
		if (j == ans.size()) return false;
		++j;
	}
	mxq = max(mxq, (int)a.size());
	
	return true;
}
#else
#include "grader.h"
#define debug(...) 0
#define DE(...) 0
#endif
const int MAX_N = 300010;
const vector<int> zero{0}, one{1};
int n;
bool query(vector<int> a) {
	if (a.size() > n) return false;
	return isSubsequence(a);
}

vector<int> operator + (vector<int> a, vector<int> b) {
	a.insert(end(a), AI(b));
	return a;
}
vector<int> findSequence(int _n) {
	n = _n;
	DE(n);
	vector<int> Z, O, ans;
	while (true) {
		bool go = true;
		if (query(Z + zero))
			Z.pb(0);
		else go = false;

		if (query(O + one))
			O.pb(1);
		else go = false;

		if (!go) break;
	}

	DE(O.size(), Z.size());

	if (query(O + one)) {
		while (O.size() + Z.size() < n)
			O.pb(1);
	}
	else {
		while (O.size() + Z.size() < n)
			Z.pb(0);
	}

	if (Z.empty() || O.empty())
		return Z.empty() ? O : Z;

	vector<int> cnt(n+1);
	vector<vector<int>> ad(n+1);
	DE(__LINE__);
	// insert into zeroes
	if (Z.size() < O.size()) {
		int zs = Z.size();

		int ok = Z.size() + 1, pos = -1, sum = 0;
		while (ok > 1) {
			ok = 0, pos = -1;
			for (int i = 0;i <= Z.size();++i) {
				if (query(vector<int>(i, 0) + ad[i] + one + vector<int>(zs-i, 0)))
					ad[i].pb(1), ++ok, pos = i, ++sum;
			}
			if (ok == 1) {
				int U = O.size() - sum;
				while (U--)
					ad[pos].pb(1);
			}
		}

		for (int i = 0;i <= Z.size();++i) {
			ans = ans + ad[i];

			if (i < Z.size())
				ans.pb(0);
		}
	}
	else {
		// insert into ones
		int zs = O.size();

		int ok = O.size() + 1, pos = -1, sum = 0;
		while (ok > 1) {
			ok = 0, pos = -1;
			for (int i = 0;i <= O.size();++i) {
				if (query(vector<int>(i, 1) + ad[i] + zero + vector<int>(zs-i, 1)))
					ad[i].pb(0), ++ok, pos = i, ++sum;
			}
			if (ok == 1) {
				int U = Z.size() - sum;
				while (U--)
					ad[pos].pb(0);
			}
		}

		for (int i = 0;i <= O.size();++i) {
			ans = ans + ad[i];

			if (i < O.size())
				ans.pb(1);
		}
	}
	return ans;

}

#ifdef KEV
int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	vector<int> res = findSequence(ans.size());
	if (res == ans) {
		cerr << "AC!\n";
		DE(mxq);
	}
	else {
		cerr << "WA\n";
		debug(AI(res));
		cerr << "Should be\n";
		debug(AI(ans));
	}
}
#endif

Compilation message

hidden.cpp: In function 'bool query(std::vector<int>)':
hidden.cpp:34:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |  if (a.size() > n) return false;
      |      ~~~~~~~~~^~~
hidden.cpp: In function 'std::vector<int> findSequence(int)':
hidden.cpp:28:17: warning: statement has no effect [-Wunused-value]
   28 | #define DE(...) 0
      |                 ^
hidden.cpp:44:2: note: in expansion of macro 'DE'
   44 |  DE(n);
      |  ^~
hidden.cpp:28:17: warning: statement has no effect [-Wunused-value]
   28 | #define DE(...) 0
      |                 ^
hidden.cpp:59:2: note: in expansion of macro 'DE'
   59 |  DE(O.size(), Z.size());
      |  ^~
hidden.cpp:62:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   62 |   while (O.size() + Z.size() < n)
      |          ~~~~~~~~~~~~~~~~~~~~^~~
hidden.cpp:66:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   66 |   while (O.size() + Z.size() < n)
      |          ~~~~~~~~~~~~~~~~~~~~^~~
hidden.cpp:28:17: warning: statement has no effect [-Wunused-value]
   28 | #define DE(...) 0
      |                 ^
hidden.cpp:75:2: note: in expansion of macro 'DE'
   75 |  DE(__LINE__);
      |  ^~
hidden.cpp:83:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |    for (int i = 0;i <= Z.size();++i) {
      |                   ~~^~~~~~~~~~~
hidden.cpp:94:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |   for (int i = 0;i <= Z.size();++i) {
      |                  ~~^~~~~~~~~~~
hidden.cpp:97:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |    if (i < Z.size())
      |        ~~^~~~~~~~~~
hidden.cpp:108:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |    for (int i = 0;i <= O.size();++i) {
      |                   ~~^~~~~~~~~~~
hidden.cpp:119:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  119 |   for (int i = 0;i <= O.size();++i) {
      |                  ~~^~~~~~~~~~~
hidden.cpp:122:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |    if (i < O.size())
      |        ~~^~~~~~~~~~
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 Partially correct 1 ms 256 KB Output is partially correct: Maximum length of a query = 6
2 Partially correct 1 ms 256 KB Output is partially correct: Maximum length of a query = 7
3 Partially correct 1 ms 384 KB Output is partially correct: Maximum length of a query = 7
4 Partially correct 1 ms 256 KB Output is partially correct: Maximum length of a query = 6
5 Partially correct 1 ms 256 KB Output is partially correct: Maximum length of a query = 6
# Verdict Execution time Memory Grader output
1 Partially correct 12 ms 376 KB Output is partially correct: Maximum length of a query = 85
2 Correct 17 ms 376 KB Output is correct: Maximum length of a query = 90
3 Partially correct 15 ms 256 KB Output is partially correct: Maximum length of a query = 101
4 Partially correct 10 ms 376 KB Output is partially correct: Maximum length of a query = 81
5 Partially correct 17 ms 384 KB Output is partially correct: Maximum length of a query = 102
6 Partially correct 26 ms 256 KB Output is partially correct: Maximum length of a query = 100
7 Partially correct 92 ms 504 KB Output is partially correct: Maximum length of a query = 144
8 Partially correct 26 ms 376 KB Output is partially correct: Maximum length of a query = 94
9 Partially correct 24 ms 384 KB Output is partially correct: Maximum length of a query = 110
10 Partially correct 58 ms 376 KB Output is partially correct: Maximum length of a query = 125
11 Partially correct 9 ms 384 KB Output is partially correct: Maximum length of a query = 97
12 Partially correct 112 ms 504 KB Output is partially correct: Maximum length of a query = 150
13 Partially correct 21 ms 376 KB Output is partially correct: Maximum length of a query = 106