Submission #67810

# Submission time Handle Problem Language Result Execution time Memory
67810 2018-08-15T10:12:45 Z cdemirer Binary Subsequences (info1cup17_binary) C++17
43 / 100
106 ms 744 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef pair<double, double> dodo;
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)

#define LIM (2000)

int N;
int tcs[2000];

vi ans1;
vii ans2;

void func(int total, int v1, int v2) {
	if (total > LIM) return;
	ans1[total]++;
	int val = total + 1;
	func(total + val-v1, val, v2);
	func(total + val-v2, v1, val);
}
void precalc() {
	for (int m = 0; m < (1<<20)-1; m++) {
	//int m = 0;
		int last1val = 0, last0val = 0;
		int total = 0;
		int pm = 0;
		for (int i = 0; i < 20; i++) {
			//cerr << "DBG" << " " << m << " " << i << " " << total << endl;
			//cerr << "m&asdas: " << (m & (1<<i)) << endl;
			pm |= (m & (1<<i));
			int val = total + 1;
			bool type = m & (1<<i);
			if (type) {
				val -= last1val;
				last1val += val;
			} else {
				val -= last0val;
				last0val += val;
			}
			//cerr << val << endl;
			total += val;
			if (total > LIM) break;
			if (pm == m) {
				//cerr << ": " << total << endl;
				//ans1[total]++;
				if (ans2[total] == mp(-1, -1) || i < ans2[total].second) ans2[total] = mp(pm, i);
			}
		}
	}
}

void solve12() {
	ans1.resize(LIM+1);
	ans2.resize(LIM+1);
	fill(ans2.begin(), ans2.end(), mp(-1, -1));
	
	func(0, 0, 0);
	precalc();
	//cerr << "DBG" << endl;
	for (int i = 0; i < N; i++) {
		//cout << tcs[i] << " ";
		//cout << -1 << '\n';
		cout << ans1[ tcs[i] ] << '\n';
		for (int k = 0; k <= ans2[ tcs[i] ].second; k++) {
			cout << (bool)( ans2[ tcs[i] ].first & (1<<k) ) << " ";
		}
		cout << '\n';
	}
	//cerr << "DBG" << endl;
}

int main(int argc, char **argv) {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> N;
	for (int i = 0; i < N; i++) cin >> tcs[i];
	
	if (all_of(tcs, tcs+N, [](int x){return x <= 100000;})) solve12();
	else exit(-1);

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 105 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 106 ms 744 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 744 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -