Submission #389580

# Submission time Handle Problem Language Result Execution time Memory
389580 2021-04-14T07:40:05 Z casperwang Binary Subsequences (info1cup17_binary) C++14
0 / 100
336 ms 704 KB
#include <bits/stdc++.h>
#define int long long
#define pb emplace_back
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }

const int MAXN = 2000;
const int K = 11;
const int INF = 1e18;
int T, N;
vector <string> arr;
vector <string> tmp;
bool ans[MAXN+1];
string str[MAXN+1];

bool check(const string &a, const string &b) {
	int j = 0;
	for (int i = 0; i < a.size(); i++) {
		if (j < b.size() && a[i] == b[j]) j++;
		if (j == b.size()) break;
	}
	return j == b.size();
}

void init() {
	for (int i = 1; i <= K; i++) {
		for (int j = 0; j < (1<<i); j++) {
			string now = "";
			for (int k = 0; k < i; k++)
				now += ((j & (1<<k)) ? '1' : '0');
			int cnt = 1;
			for (string s : arr) cnt += check(now, s);
			if (ans[cnt] == 0)
				str[cnt] = now;
			ans[cnt]++;
			tmp.pb(now);
		}
		for (string s: tmp) arr.pb(s);
		tmp.clear();
	}
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	init();
	for (int N = 1; N <= MAXN; N++) {
		cout << ans[N] << '\n';
		if (ans[N]) {
			for (int i = 0; i < str[N].size(); i++)
				cout << str[N][i] << " \n"[i==str[N].size()-1];
		} else {
			cout << -1 << '\n';
		}
	}
	return 0;
}

Compilation message

binary.cpp: In function 'bool check(const string&, const string&)':
binary.cpp:21:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |  for (int i = 0; i < a.size(); i++) {
      |                  ~~^~~~~~~~~~
binary.cpp:22:9: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |   if (j < b.size() && a[i] == b[j]) j++;
      |       ~~^~~~~~~~~~
binary.cpp:23:9: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   if (j == b.size()) break;
      |       ~~^~~~~~~~~~~
binary.cpp:25:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  return j == b.size();
      |         ~~^~~~~~~~~~~
binary.cpp: In function 'void init()':
binary.cpp:38:12: warning: use of an operand of type 'bool' in 'operator++' is deprecated [-Wdeprecated]
   38 |    ans[cnt]++;
      |            ^~
binary.cpp: In function 'int main()':
binary.cpp:52:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |    for (int i = 0; i < str[N].size(); i++)
      |                    ~~^~~~~~~~~~~~~~~
binary.cpp:53:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     cout << str[N][i] << " \n"[i==str[N].size()-1];
      |                                ~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 305 ms 704 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 306 ms 696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 336 ms 636 KB Output isn't correct
2 Halted 0 ms 0 KB -