Submission #128696

# Submission time Handle Problem Language Result Execution time Memory
128696 2019-07-11T08:30:52 Z E869120 Binary Subsequences (info1cup17_binary) C++14
0 / 100
900 ms 19108 KB
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#pragma warning (disable: 4996)

int len[250], mask[250];

void hantei(int dig, int masks) {
	vector<int>P[20];
	for (int i = 0; i < dig; i++) {
		int s = 0;
		for (int j = i; j < dig; j++) {
			// 区間 [i, j]
			s += (1 << j);
			P[j - i].push_back(masks&s);
		}
	}

	int cnt = 0;
	for (int i = 0; i < dig; i++) {
		sort(P[i].begin(), P[i].end());
		P[i].erase(unique(P[i].begin(), P[i].end()), P[i].end());
		cnt += P[i].size();
	}

	if (len[cnt] > dig) {
		len[cnt] = dig;
		mask[cnt] = masks;
	}
}

void init() {
	for (int i = 0; i < 250; i++) { len[i] = (1 << 30); mask[i] = -1; }

	for (int i = 1; i <= 14; i++) {
		for (int j = 0; j < (1 << i); j++) hantei(i, j);
	}
}

void solve(int A) {
	if (A >= 250 || len[A] == 0) {
		cout << "-1" << endl;
		cout << "-1" << endl;
	}
	else {
		cout << len[A] << endl;
		for (int i = 0; i < len[A]; i++) {
			if (i) cout << " ";
			cout << (mask[A] / (1 << i)) % 2;
		}
		cout << endl;
	}
}

int main() {
	init();
	int T; scanf("%d", &T);
	for (int i = 1; i <= T; i++) {
		int K; scanf("%d", &K);
		solve(K);
	}
	return 0;
}

Compilation message

binary.cpp:5:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning (disable: 4996)
 
binary.cpp: In function 'int main()':
binary.cpp:58:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int T; scanf("%d", &T);
         ~~~~~^~~~~~~~~~
binary.cpp:60:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int K; scanf("%d", &K);
          ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 19108 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Incorrect 115 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 115 ms 356 KB Output isn't correct
2 Halted 0 ms 0 KB -