Submission #1286624

#TimeUsernameProblemLanguageResultExecution timeMemory
1286624thuhienneZalmoxis (BOI18_zalmoxis)C++20
100 / 100
859 ms145312 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define re exit(0);
#define thuhien "zalmosis"

int n,k;
vector <int> s;

struct range {
	int val;
	vector <pair <int,bool>> container;
};

vector <range> arr,temp;

multiset <int> a;
multiset <int>::iterator it;

void print(int val) {
	a.clear();
	a.insert(val);
	while (k && *a.rbegin() != 1) {
		it = a.end();it--;
		a.insert(*it - 1);a.insert(*it - 1);
		a.erase(it);
		k--;
	}
	for (auto x : a) cout << x << " ";
}

int main() {
  ios_base::sync_with_stdio(0);cin.tie(nullptr);
	if (fopen(thuhien".inp","r")) {
		freopen(thuhien".inp","r",stdin);
		freopen(thuhien".out","w",stdout);
	}

	cin >> n >> k;
	arr.resize(n);
	for (int i = 0;i < n;i++) {
		int a;cin >> a;
		arr[i] = {a,{{a,0}}};
	}
	
	for (int tt = 0;tt <= 29;tt++) {
		temp.clear();
		for (auto x : arr) {
			if (temp.size() && temp.back().val == tt && x.val == tt) {
				
				temp.back().val++;
				for (auto a : x.container) temp.back().container.push_back(a);
				
			} else temp.push_back(x);
		}
		
		arr.clear();
		arr = temp;
		
		for (int i = 0;i < arr.size();i++) if (arr[i].val == tt) {
			arr[i].val++;
			arr[i].container.push_back({tt,1});
			k--;
		}
		
	}
	
	for (auto x : arr[0].container) {
		if (!x.second) cout << x.first << " ";
		else print(x.first);
	}

}

Compilation message (stderr)

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:37:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |                 freopen(thuhien".inp","r",stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
zalmoxis.cpp:38:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |                 freopen(thuhien".out","w",stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...