Submission #61910

#TimeUsernameProblemLanguageResultExecution timeMemory
61910khsoo01Zalmoxis (BOI18_zalmoxis)C++11
100 / 100
379 ms10740 KiB
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

int n, k;

vector<int> cur;
vector<pii> ans;

void upd () {
	while(cur.size() >= 2) {
		int A = cur.back();
		cur.pop_back();
		int B = cur.back();
		cur.pop_back();
		if(A != B) {
			cur.push_back(B);
			cur.push_back(A);
			return;
		}
		else cur.push_back(A+1);
	}
}

void print (int V) {
	if(V && k) {
		k--;
		print(V-1);
		print(V-1);
	}
	else {
		printf("%d ",V);
		return;
	}
}

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) {
		int T;
		scanf("%d",&T);
		while(!cur.empty() && T > cur.back()) {
			ans.push_back({cur.back(), 1});
			k--;
			cur.push_back(cur.back());
			upd();
		}
		ans.push_back({T, 0});
		cur.push_back(T);
		upd();
	}
	while(cur[0] < 30) {
		ans.push_back({cur.back(), 1});
		k--;
		cur.push_back(cur.back());
		upd();
	}
	for(auto &T : ans) {
		int A, B;
		tie(A, B) = T;
		if(B) print(A);
		else printf("%d ",A);
	}
}

Compilation message (stderr)

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&k);
  ~~~~~^~~~~~~~~~~~~~
zalmoxis.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&T);
   ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...