답안 #709835

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
709835 2023-03-14T16:20:30 Z rainboy Let's Win the Election (JOI22_ho_t3) C
100 / 100
186 ms 340 KB
#include <stdio.h>
#include <string.h>

#define N	500
#define INF	0x3f3f3f3f

double min(double a, double b) { return a < b ? a : b; }

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

int aa[N], bb[N];

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (bb[ii[j]] == bb[i_])
				j++;
			else if (bb[ii[j]] < bb[i_]) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		sort(ii, l, i);
		l = k;
	}
}

int main() {
	static int ii[N];
	static char cc[N], cc_[N];
	int n, k, l, l_, h, i, i_, i1, j;
	double x, x_, d, d_, d1, ans;

	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++) {
		scanf("%d%d", &aa[i], &bb[i]);
		if (bb[i] == -1)
			bb[i] = INF;
	}
	for (i = 0; i < n; i++)
		ii[i] = i;
	sort(ii, 0, n);
	ans = INF;
	x = 0;
	for (l = 0; l <= k && (l == 0 || bb[ii[l - 1]] != INF); l++) {
		if (l > 0)
			cc[l - 1] = 1, x += (double) bb[ii[l - 1]] / l;
		memcpy(cc_, cc, n * sizeof *cc);
		x_ = x;
		for (h = l; h < k; h++) {
			for (j = 0; j < n; j++)
				if (cc_[j] == 0)
					break;
			d = (double) bb[ii[j]] / l, d1 = INF, i1 = -1;
			for (i = n - 1, l_ = l; i >= 0; i--) {
				i_ = ii[i];
				if (cc_[i] == 0) {
					if (d1 > (d_ = (double) aa[i_] / (l + 1)))
						d1 = d_, i1 = i;
				} else if (cc_[i] == 1) {
					if (d1 > (d_ = (double) aa[i_] / (l + 1) - (double) bb[i_] / l_ + d))
						d1 = d_, i1 = i;
					if (l_ > 1)
						d += (double) bb[i_] / (l_ - 1) - (double) bb[i_] / l_, l_--;
				}
			}
			x_ += d1;
			if (cc_[i1] == 0)
				cc_[i1] = -1;
			else
				cc_[i1] = -1, cc_[j] = 1;
		}
		ans = min(ans, x_);
	}
	printf("%f\n", ans);
	return 0;
}

Compilation message

Main.c: In function 'main':
Main.c:42:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |  scanf("%d%d", &n, &k);
      |  ^~~~~~~~~~~~~~~~~~~~~
Main.c:44:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |   scanf("%d%d", &aa[i], &bb[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 12 ms 288 KB Output is correct
13 Correct 12 ms 212 KB Output is correct
14 Correct 11 ms 288 KB Output is correct
15 Correct 75 ms 268 KB Output is correct
16 Correct 73 ms 212 KB Output is correct
17 Correct 30 ms 212 KB Output is correct
18 Correct 181 ms 272 KB Output is correct
19 Correct 137 ms 272 KB Output is correct
20 Correct 43 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 292 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 296 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 296 KB Output is correct
28 Correct 0 ms 224 KB Output is correct
29 Correct 0 ms 216 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 296 KB Output is correct
34 Correct 1 ms 224 KB Output is correct
35 Correct 0 ms 224 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 292 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 292 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 296 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 296 KB Output is correct
28 Correct 0 ms 224 KB Output is correct
29 Correct 0 ms 216 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 296 KB Output is correct
34 Correct 1 ms 224 KB Output is correct
35 Correct 0 ms 224 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 292 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 216 KB Output is correct
44 Correct 1 ms 216 KB Output is correct
45 Correct 1 ms 292 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 292 KB Output is correct
49 Correct 2 ms 288 KB Output is correct
50 Correct 2 ms 212 KB Output is correct
51 Correct 2 ms 212 KB Output is correct
52 Correct 2 ms 212 KB Output is correct
53 Correct 2 ms 292 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 2 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 292 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 2 ms 212 KB Output is correct
60 Correct 2 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 178 ms 272 KB Output is correct
2 Correct 186 ms 268 KB Output is correct
3 Correct 177 ms 272 KB Output is correct
4 Correct 179 ms 332 KB Output is correct
5 Correct 174 ms 272 KB Output is correct
6 Correct 175 ms 212 KB Output is correct
7 Correct 173 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 12 ms 288 KB Output is correct
13 Correct 12 ms 212 KB Output is correct
14 Correct 11 ms 288 KB Output is correct
15 Correct 75 ms 268 KB Output is correct
16 Correct 73 ms 212 KB Output is correct
17 Correct 30 ms 212 KB Output is correct
18 Correct 181 ms 272 KB Output is correct
19 Correct 137 ms 272 KB Output is correct
20 Correct 43 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 292 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 292 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 0 ms 296 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 296 KB Output is correct
48 Correct 0 ms 224 KB Output is correct
49 Correct 0 ms 216 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 296 KB Output is correct
54 Correct 1 ms 224 KB Output is correct
55 Correct 0 ms 224 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 1 ms 292 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 1 ms 212 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 216 KB Output is correct
64 Correct 1 ms 216 KB Output is correct
65 Correct 1 ms 292 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 1 ms 212 KB Output is correct
68 Correct 1 ms 292 KB Output is correct
69 Correct 2 ms 288 KB Output is correct
70 Correct 2 ms 212 KB Output is correct
71 Correct 2 ms 212 KB Output is correct
72 Correct 2 ms 212 KB Output is correct
73 Correct 2 ms 292 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 2 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 292 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 2 ms 212 KB Output is correct
80 Correct 2 ms 212 KB Output is correct
81 Correct 178 ms 272 KB Output is correct
82 Correct 186 ms 268 KB Output is correct
83 Correct 177 ms 272 KB Output is correct
84 Correct 179 ms 332 KB Output is correct
85 Correct 174 ms 272 KB Output is correct
86 Correct 175 ms 212 KB Output is correct
87 Correct 173 ms 212 KB Output is correct
88 Correct 3 ms 212 KB Output is correct
89 Correct 2 ms 292 KB Output is correct
90 Correct 8 ms 296 KB Output is correct
91 Correct 9 ms 292 KB Output is correct
92 Correct 42 ms 276 KB Output is correct
93 Correct 34 ms 212 KB Output is correct
94 Correct 89 ms 276 KB Output is correct
95 Correct 90 ms 212 KB Output is correct
96 Correct 138 ms 272 KB Output is correct
97 Correct 138 ms 212 KB Output is correct
98 Correct 79 ms 268 KB Output is correct
99 Correct 76 ms 272 KB Output is correct
100 Correct 76 ms 276 KB Output is correct
101 Correct 79 ms 272 KB Output is correct
102 Correct 76 ms 212 KB Output is correct
103 Correct 76 ms 212 KB Output is correct
104 Correct 74 ms 276 KB Output is correct
105 Correct 73 ms 272 KB Output is correct