Submission #272385

# Submission time Handle Problem Language Result Execution time Memory
272385 2020-08-18T11:38:05 Z theStaticMind Binary Subsequences (info1cup17_binary) C++14
82 / 100
900 ms 408 KB
#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;

int f(int x, int y){
	if(x == 0 || y == 0) return max(x, y);
	if(x == y) return INF;
	if(x > y){
		return f(x - y - 1, y) + 1;
	}
	else{
		return f(x, y - x - 1) + 1;
	}
}

void get(int x, int y, string &s){
	if(x == 0 && y == 0) return;
	if(x > y){
		s.pb('0');
		get(x - y - 1, y, s);
	}
	else{
		s.pb('1');
		get(x, y - x - 1, s);
	}
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int q;
	cin >> q;
	while(q--){
		int k, ans = 0;
		ii mn = {INF, -1};
		cin >> k;

		for(int i = 0; i <= k/2; i++){
			int c = f(i, k - i);
			if(c < INF){
				mn = min(mn, {c, i});
				ans += 2;
			}
		}

		string s;
		get(mn.second, k - mn.second, s);

		cout << ans << "\n";
		reverse(all(s));
		for(auto p : s) cout << p << " ";
		cout << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 102 ms 408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 384 KB Output is correct
2 Correct 87 ms 384 KB Output is correct
3 Correct 97 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -