Submission #63591

#TimeUsernameProblemLanguageResultExecution timeMemory
63591BruteforcemanZalmoxis (BOI18_zalmoxis)C++11
5 / 100
1095 ms63340 KiB
#include <bits/stdc++.h>
using namespace std;
int a[1000010];
vector <int> v[1000010];
int alive[1000010];

int main(int argc, char const *argv[])
{
	int n, k;
	scanf("%d %d", &n, &k);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		alive[i] = 1;
		v[i].emplace_back(a[i]);
	}
	int sz = n;
	while(sz < n + k) {
		int opt = -1;
		for(int i = 1; i <= n; i++) {
			if(alive[i] == 1) {
				if(opt == -1 || a[opt] >= a[i]) {
					opt = i;
				}
			}
		}
		if(a[opt] == 30) break;
		int prev = -1;
		for(int i = opt - 1; i >= 1; i--) {
			if(alive[i] == 1) {
				prev = i;
				break;
			}
		}
		if(prev == -1 || a[prev] > a[opt]) {
			v[opt].emplace_back(a[opt]);
			++a[opt];
			++sz;
		} else {
			alive[prev] = 0;
			++a[opt];
		}
	}
	for(int i = 1; i <= n; i++) {
		vector <int> tmp;
		while(v[i].size() > 1 && sz < n + k) {
			if(v[i].back() > 1) {
				int x = v[i].back();
				v[i].pop_back();
				v[i].emplace_back(x - 1);
				v[i].emplace_back(x - 1);
				++sz;	
			} else {
				v[i].pop_back();
				tmp.emplace_back(1);
			}
		}
		for(auto j : tmp) {
			v[i].emplace_back(j);
		}
		for(auto j : v[i]) {
			printf("%d ", j);
		}
	}
	printf("\n");
	return 0;
}

Compilation message (stderr)

zalmoxis.cpp: In function 'int main(int, const char**)':
zalmoxis.cpp:10: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:12:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...