Submission #544742

# Submission time Handle Problem Language Result Execution time Memory
544742 2022-04-02T16:21:37 Z rainboy Zalmoxis (BOI18_zalmoxis) C
100 / 100
196 ms 9568 KB
#include <stdio.h>

#define N	1000000
#define M	30

int k;

void print(int a) {
	if (a == 0 || k == 0) {
		printf("%d ", a);
		return;
	}
	k--;
	print(a - 1), print(a - 1);
}

int main() {
	static int aa[N], qu[M + 1];
	static char fixed[N];
	int n, n_, i, cnt;

	scanf("%d%d", &n, &k);
	n_ = 0, cnt = 0;
	for (i = 0; i < n; i++) {
		int a;

		scanf("%d", &a);
		while (cnt && qu[cnt - 1] < a) {
			while ((cnt < 2 || qu[cnt - 1] < qu[cnt - 2]) && qu[cnt - 1] < a)
				aa[n_++] = qu[cnt - 1]++;
			while (cnt >= 2 && qu[cnt - 1] == qu[cnt - 2])
				qu[--cnt - 1]++;
		}
		qu[cnt++] = a;
		while (cnt >= 2 && qu[cnt - 1] == qu[cnt - 2])
			qu[--cnt - 1]++;
		aa[n_] = a, fixed[n_] = 1, n_++;
	}
	while (cnt >= 2) {
		aa[n_++] = qu[cnt - 1]++;
		while (cnt >= 2 && qu[cnt - 1] == qu[cnt - 2])
			qu[--cnt - 1]++;
	}
	while (qu[cnt - 1] < M)
		aa[n_++] = qu[cnt - 1]++;
	k -= n_ - n, n = n_;
	for (i = 0; i < n; i++)
		if (fixed[i])
			printf("%d ", aa[i]);
		else
			print(aa[i]);
	printf("\n");
	return 0;
}

Compilation message

zalmoxis.c: In function 'main':
zalmoxis.c:22:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |  scanf("%d%d", &n, &k);
      |  ^~~~~~~~~~~~~~~~~~~~~
zalmoxis.c:27:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   scanf("%d", &a);
      |   ^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 194 ms 9364 KB Output is correct
2 Correct 157 ms 9280 KB Output is correct
3 Correct 162 ms 9292 KB Output is correct
4 Correct 196 ms 9260 KB Output is correct
5 Correct 157 ms 9292 KB Output is correct
6 Correct 161 ms 9252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 160 ms 9192 KB Output is correct
2 Correct 158 ms 9264 KB Output is correct
3 Correct 163 ms 9260 KB Output is correct
4 Correct 165 ms 9568 KB Output is correct
5 Correct 160 ms 9292 KB Output is correct
6 Correct 169 ms 9220 KB Output is correct
7 Correct 157 ms 9292 KB Output is correct
8 Correct 156 ms 9296 KB Output is correct
9 Correct 150 ms 8524 KB Output is correct
10 Correct 100 ms 5076 KB Output is correct
11 Correct 114 ms 6536 KB Output is correct
12 Correct 68 ms 2244 KB Output is correct
13 Correct 71 ms 2236 KB Output is correct
14 Correct 65 ms 2248 KB Output is correct