Submission #862143

#TimeUsernameProblemLanguageResultExecution timeMemory
862143iskhakkutbilimZalmoxis (BOI18_zalmoxis)C++17
100 / 100
191 ms22452 KiB
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
int n, k;
vector<pair<int, int> > ans;
int cur;
vector<int> a;
void f(int x){
	if(x < 0) return;
	if(cur >= n or a[cur] >= x){
		if(cur < n && a[cur] == x){
			ans.push_back({x, 0});
			cur++;
		}else{
			ans.push_back({x, 1});
		}
	}else{
		f(x-1);
		f(x-1);
	}
}
vector<int> all;
void split(int x){
	if(k == 0 or x == 0){
		all.push_back(x);
	}else{
		k--;
		split(x-1);
		split(x-1);
	}
} 
 
 
main(){
	cin >> n >> k;
	a.resize(n);
	for(int i = 0;i < n; i++){
		cin >> a[i];
	}

	f(30);
	if(ans.size() == n + k){
		for(auto [x, y] : ans) cout << x << ' ';
		return 0;
	}
	k = k - (int)ans.size() + n;
	for(auto [x, y] : ans){
		if(!y){
			all.push_back(x);
			continue;
		}
		split(x);
	}
	for(int x : all) cout << x << ' ';
	return 0;
}

Compilation message (stderr)

zalmoxis.cpp:37:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   37 | main(){
      | ^~~~
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:45:16: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |  if(ans.size() == n + k){
      |     ~~~~~~~~~~~^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...