Submission #722769

# Submission time Handle Problem Language Result Execution time Memory
722769 2023-04-12T20:18:55 Z rainboy Card Scoring (CCO19_day2problem1) C++17
5 / 100
198 ms 167072 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.cpp: In function 'int main()':
Main.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  scanf("%lf%d", &k, &n), k /= 2;
      |  ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |   scanf("%d", &a), a--;
      |   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 292 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Runtime error 2 ms 468 KB Execution killed with signal 6
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Runtime error 2 ms 468 KB Execution killed with signal 6
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 198 ms 167072 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 292 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 352 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Runtime error 2 ms 468 KB Execution killed with signal 6
16 Halted 0 ms 0 KB -