답안 #693001

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
693001 2023-02-02T08:35:09 Z bdl Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
190 ms 2276 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <array>
#include <iostream>
using namespace std;

#define ar array

const int N = 500, INF = 1e9;
const long long INF_LL = 1e18;

int main() {
  int n, k;
  scanf("%d", &n);
  scanf("%d", &k);
  static ar<int, 2> a[N];
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a[i][1], &a[i][0]);
    if (a[i][0] == -1)
      a[i][0] = INF;
  }
  sort(a, a + n);
  static long long sm[N + 1][N + 1];
  for (int i = n - 1; i >= 0; i--)
    for (int j = 1; j <= n - i; j++)
      sm[i][j] = min(a[i][1] + sm[i + 1][j - 1], j != n - i ? sm[i + 1][j] : INF_LL);
  double ans = sm[0][k];
  for (int t = 1; t <= k; t++) {
    static double f[N + 1];
    for (int i = 1; i <= t; i++)
      f[i] = INF_LL;
    f[0] = 0;
    for (int i = 0; i < n; i++) {
      for (int j = t; j >= 0; j--)
        f[j] = min(f[j] + (double) a[i][1] / (t + 1), j == 0 ? INF_LL : f[j - 1] + (double) a[i][0] / j);
      if (i >= t - 1 && k - i > 0)
        ans = min(ans, f[t] + (double) sm[i + 1][k - i - 1] / (t + 1));
    }
  }
  printf("%.4lf\n", ans);
  return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
Main.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |   scanf("%d", &k);
      |   ~~~~~^~~~~~~~~~
Main.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     scanf("%d%d", &a[i][1], &a[i][0]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Correct 13 ms 2264 KB Output is correct
7 Correct 49 ms 2240 KB Output is correct
8 Correct 106 ms 2244 KB Output is correct
9 Correct 186 ms 2260 KB Output is correct
10 Correct 92 ms 2240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Correct 13 ms 2264 KB Output is correct
7 Correct 49 ms 2240 KB Output is correct
8 Correct 106 ms 2244 KB Output is correct
9 Correct 186 ms 2260 KB Output is correct
10 Correct 92 ms 2240 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 18 ms 2260 KB Output is correct
13 Correct 19 ms 2260 KB Output is correct
14 Correct 18 ms 2260 KB Output is correct
15 Correct 96 ms 2240 KB Output is correct
16 Correct 92 ms 2260 KB Output is correct
17 Correct 92 ms 2132 KB Output is correct
18 Correct 190 ms 2260 KB Output is correct
19 Correct 185 ms 2260 KB Output is correct
20 Correct 186 ms 2264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 304 KB Output is correct
26 Correct 0 ms 308 KB Output is correct
27 Correct 0 ms 308 KB Output is correct
28 Correct 0 ms 308 KB Output is correct
29 Correct 1 ms 304 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 308 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 304 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 304 KB Output is correct
26 Correct 0 ms 308 KB Output is correct
27 Correct 0 ms 308 KB Output is correct
28 Correct 0 ms 308 KB Output is correct
29 Correct 1 ms 304 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 308 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 304 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 1 ms 692 KB Output is correct
42 Correct 1 ms 692 KB Output is correct
43 Correct 1 ms 692 KB Output is correct
44 Correct 1 ms 596 KB Output is correct
45 Correct 1 ms 692 KB Output is correct
46 Correct 1 ms 692 KB Output is correct
47 Correct 1 ms 596 KB Output is correct
48 Correct 1 ms 596 KB Output is correct
49 Correct 2 ms 596 KB Output is correct
50 Correct 2 ms 596 KB Output is correct
51 Correct 2 ms 596 KB Output is correct
52 Correct 2 ms 700 KB Output is correct
53 Correct 1 ms 596 KB Output is correct
54 Correct 1 ms 696 KB Output is correct
55 Correct 1 ms 596 KB Output is correct
56 Correct 1 ms 596 KB Output is correct
57 Correct 1 ms 596 KB Output is correct
58 Correct 2 ms 596 KB Output is correct
59 Correct 2 ms 696 KB Output is correct
60 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 186 ms 2260 KB Output is correct
2 Correct 186 ms 2260 KB Output is correct
3 Correct 183 ms 2260 KB Output is correct
4 Correct 182 ms 2260 KB Output is correct
5 Correct 189 ms 2260 KB Output is correct
6 Correct 187 ms 2260 KB Output is correct
7 Correct 190 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Correct 13 ms 2264 KB Output is correct
7 Correct 49 ms 2240 KB Output is correct
8 Correct 106 ms 2244 KB Output is correct
9 Correct 186 ms 2260 KB Output is correct
10 Correct 92 ms 2240 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 18 ms 2260 KB Output is correct
13 Correct 19 ms 2260 KB Output is correct
14 Correct 18 ms 2260 KB Output is correct
15 Correct 96 ms 2240 KB Output is correct
16 Correct 92 ms 2260 KB Output is correct
17 Correct 92 ms 2132 KB Output is correct
18 Correct 190 ms 2260 KB Output is correct
19 Correct 185 ms 2260 KB Output is correct
20 Correct 186 ms 2264 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 304 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 1 ms 304 KB Output is correct
46 Correct 0 ms 308 KB Output is correct
47 Correct 0 ms 308 KB Output is correct
48 Correct 0 ms 308 KB Output is correct
49 Correct 1 ms 304 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 0 ms 308 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
54 Correct 0 ms 340 KB Output is correct
55 Correct 0 ms 304 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 0 ms 340 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 0 ms 340 KB Output is correct
61 Correct 1 ms 692 KB Output is correct
62 Correct 1 ms 692 KB Output is correct
63 Correct 1 ms 692 KB Output is correct
64 Correct 1 ms 596 KB Output is correct
65 Correct 1 ms 692 KB Output is correct
66 Correct 1 ms 692 KB Output is correct
67 Correct 1 ms 596 KB Output is correct
68 Correct 1 ms 596 KB Output is correct
69 Correct 2 ms 596 KB Output is correct
70 Correct 2 ms 596 KB Output is correct
71 Correct 2 ms 596 KB Output is correct
72 Correct 2 ms 700 KB Output is correct
73 Correct 1 ms 596 KB Output is correct
74 Correct 1 ms 696 KB Output is correct
75 Correct 1 ms 596 KB Output is correct
76 Correct 1 ms 596 KB Output is correct
77 Correct 1 ms 596 KB Output is correct
78 Correct 2 ms 596 KB Output is correct
79 Correct 2 ms 696 KB Output is correct
80 Correct 1 ms 596 KB Output is correct
81 Correct 186 ms 2260 KB Output is correct
82 Correct 186 ms 2260 KB Output is correct
83 Correct 183 ms 2260 KB Output is correct
84 Correct 182 ms 2260 KB Output is correct
85 Correct 189 ms 2260 KB Output is correct
86 Correct 187 ms 2260 KB Output is correct
87 Correct 190 ms 2260 KB Output is correct
88 Correct 3 ms 2232 KB Output is correct
89 Correct 4 ms 2224 KB Output is correct
90 Correct 13 ms 2276 KB Output is correct
91 Correct 13 ms 2264 KB Output is correct
92 Correct 49 ms 2260 KB Output is correct
93 Correct 49 ms 2260 KB Output is correct
94 Correct 107 ms 2260 KB Output is correct
95 Correct 104 ms 2260 KB Output is correct
96 Correct 151 ms 2244 KB Output is correct
97 Correct 151 ms 2244 KB Output is correct
98 Correct 95 ms 2260 KB Output is correct
99 Correct 92 ms 2260 KB Output is correct
100 Correct 93 ms 2228 KB Output is correct
101 Correct 92 ms 2260 KB Output is correct
102 Correct 91 ms 2260 KB Output is correct
103 Correct 93 ms 2248 KB Output is correct
104 Correct 91 ms 2260 KB Output is correct
105 Correct 93 ms 2264 KB Output is correct