답안 #67817

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
67817 2018-08-15T10:27:41 Z cdemirer Binary Subsequences (info1cup17_binary) C++17
0 / 100
123 ms 1912 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 (100000)

int N;
int tcs[2000];

vi ans1;
vii ans2;

void func(int total, int v1, int v2, int k) {
	if (total > 2000) return;
	ans1[total] += k;
	int val = total + 1;
	if (v1 == v2) {
		func(total + val-v1, val, v2, 2*k);
	} else {
		func(total + val-v1, val, v2, k);
		func(total + val-v2, v1, val, k);
	}
}
void precalc() {
	for (int m = 0; m < (1<<20)-1; m++) {
		int last1val = 0, last0val = 0;
		int total = 0;
		int pm = 0;
		for (int i = 0; i < 20; i++) {
			pm |= (m & (1<<i));
			int val = total + 1;
			bool type = m & (1<<i);
			if (type) {
				val -= last1val;
				last1val += val;
			} else {
				val -= last0val;
				last0val += val;
			}
			total += val;
			if (total > LIM) break;
			if (pm == m) {
				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, 1);
	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 << '\n';
	for (int i = 1; i <= 50; i++) {
		cerr << i << " : " << ans1[ i ] << '\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;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 123 ms 1912 KB Extra information in the output file
# 결과 실행 시간 메모리 Grader output
1 Incorrect 123 ms 1912 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 1912 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -