답안 #478886

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478886 2021-10-08T19:37:12 Z rainboy Akvizna (COCI19_akvizna) C
130 / 130
89 ms 1872 KB
#include <stdio.h>

#define N	100000

double dp[N + 1]; int kk[N + 1], n;

double cross(int i, int j, int k) {
	return (j - i) * (dp[k] - dp[i]) - (k - i) * (dp[j] - dp[i]);
}

double eval(int i, double x) {
	return -i * x + dp[i];
}

void solve(double c) {
	static int qu[N + 1];
	int i, head, cnt;

	dp[0] = 0, kk[0] = 0;
	head = cnt = 0;
	qu[head + cnt++] = 0;
	for (i = 1; i <= n; i++) {
		while (cnt >= 2 && eval(qu[head], (double) 1 / i) < eval(qu[head + 1], (double) 1 / i))
			head++, cnt--;
		dp[i] = eval(qu[head], (double) 1 / i) + 1 - c, kk[i] = kk[qu[head]] + 1;
		while (cnt >= 2 && cross(qu[head + cnt - 2], qu[head + cnt - 1], i) >= 0)
			cnt--;
		qu[head + cnt++] = i;
	}
}

int main() {
	int k, r;
	double lower, upper;

	scanf("%d%d", &n, &k);
	lower = 0, upper = 1;
	for (r = 0; r < 60; r++) {
		double c = (lower + upper) / 2;

		solve(c);
		if (kk[n] <= k)
			upper = c;
		else
			lower = c;
	}
	solve(upper);
	printf("%.9f\n", dp[n] + k * upper);
	return 0;
}

Compilation message

akvizna.c: In function 'main':
akvizna.c:36:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |  scanf("%d%d", &n, &k);
      |  ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 420 KB Output is correct
2 Correct 3 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 3 ms 336 KB Output is correct
3 Correct 3 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 3 ms 336 KB Output is correct
3 Correct 3 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 4 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 3 ms 292 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 3 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 336 KB Output is correct
2 Correct 3 ms 336 KB Output is correct
3 Correct 3 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 336 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 4 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 1716 KB Output is correct
2 Correct 73 ms 1744 KB Output is correct
3 Correct 62 ms 1616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 1748 KB Output is correct
2 Correct 85 ms 1796 KB Output is correct
3 Correct 74 ms 1864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 1720 KB Output is correct
2 Correct 87 ms 1820 KB Output is correct
3 Correct 75 ms 1816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 1744 KB Output is correct
2 Correct 87 ms 1864 KB Output is correct
3 Correct 63 ms 1744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 1744 KB Output is correct
2 Correct 77 ms 1832 KB Output is correct
3 Correct 65 ms 1744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 1732 KB Output is correct
2 Correct 74 ms 1764 KB Output is correct
3 Correct 86 ms 1752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 1768 KB Output is correct
2 Correct 71 ms 1772 KB Output is correct
3 Correct 60 ms 1616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 1872 KB Output is correct
2 Correct 75 ms 1840 KB Output is correct
3 Correct 60 ms 1700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 1868 KB Output is correct
2 Correct 78 ms 1800 KB Output is correct
3 Correct 76 ms 1828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 1796 KB Output is correct
2 Correct 71 ms 1744 KB Output is correct
3 Correct 69 ms 1832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 1744 KB Output is correct
2 Correct 78 ms 1828 KB Output is correct
3 Correct 68 ms 1828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 1744 KB Output is correct
2 Correct 76 ms 1820 KB Output is correct
3 Correct 70 ms 1820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 1824 KB Output is correct
2 Correct 76 ms 1824 KB Output is correct
3 Correct 81 ms 1824 KB Output is correct