Submission #722768

# Submission time Handle Problem Language Result Execution time Memory
722768 2023-04-12T20:18:39 Z rainboy Card Scoring (CCO19_day2problem1) C
Compilation error
0 ms 0 KB
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

#define N	1000000

int *xx[N]; double *yy[N]; int cnt[N], cnt_[N], xx_[N], n; double k;

int crossover(int x1, double y1, int x2, double y2) {
	int lower = x2, upper = n + 1;

	while (upper - lower > 1) {
		int x = (lower + upper) / 2;

		if (y1 + pow(x - x1, k) >= y2 + pow(x - x2, k))
			upper = x;
		else
			lower = x;
	}
	return upper;
}

void add(int a, double y) {
	while (cnt[a] && crossover(xx[a][cnt[a] - 2], yy[a][cnt[a] - 2], xx[a][cnt[a] - 1], yy[a][cnt[a] - 1]) <= crossover(xx[a][cnt[a] - 1], yy[a][cnt[a] - 1], xx_[a], y))
		cnt[a]--;
	if (cnt[a] == cnt_[a]) {
		xx[a] = (int *) realloc(xx[a], cnt_[a] * 2 * sizeof *xx[a]);
		yy[a] = (double *) realloc(yy[a], cnt_[a] * 2 * sizeof *yy[a]);
	}
	xx[a][cnt[a]] = xx_[a], yy[a][cnt[a]] = y, cnt[a]++;
	xx_[a]++;
}

int main() {
	int i, a;
	double y;

	scanf("%lf%d", &k, &n), k /= 2;
	for (a = 0; a < n; a++) {
		xx[a] = (int *) malloc((cnt_[a] = 2) * sizeof *xx[a]);
		yy[a] = (double *) malloc((cnt_[a] = 2) * sizeof *yy[a]);
	}
	y = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &a), a--;
		add(a, y);
		while (cnt[a] && yy[a][cnt[a] - 1] + pow(xx_[a] - xx[a][cnt[a] - 1], k) <= yy[a][cnt[a] - 2] + pow(xx_[a] - xx[a][cnt[a] - 2], k))
			cnt[a]--;
		y = yy[a][cnt[a] - 1] + pow(xx_[a] - xx[a][cnt[a] - 1], k);
	}
	printf("%.9f\n", y);
	return 0;
}

Compilation message

Main.c: In function 'main':
Main.c:38:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  scanf("%lf%d", &k, &n), k /= 2;
      |  ^~~~~~~~~~~~~~~~~~~~~~
Main.c:45:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |   scanf("%d", &a), a--;
      |   ^~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccGl8ZGE.o: in function `crossover':
Main.c:(.text+0x63): undefined reference to `pow'
/usr/bin/ld: Main.c:(.text+0x82): undefined reference to `pow'
/usr/bin/ld: /tmp/ccGl8ZGE.o: in function `main':
Main.c:(.text.startup+0x16d): undefined reference to `pow'
/usr/bin/ld: Main.c:(.text.startup+0x1af): undefined reference to `pow'
/usr/bin/ld: Main.c:(.text.startup+0x210): undefined reference to `pow'
collect2: error: ld returned 1 exit status