Submission #936208

# Submission time Handle Problem Language Result Execution time Memory
936208 2024-03-01T12:05:45 Z weakweakweak Let's Win the Election (JOI22_ho_t3) C++14
100 / 100
1409 ms 20568 KB
//貪心(排序b,枚舉有i個b,後面就拿k-i個a)想一想發現是假的,然後就想不到了,所以看解了
#include <bits/stdc++.h>
using namespace std;

#define ld long double
#define pii pair<int, int>
#define fs first
#define sc second

int n, k, inf = 1e8, suma[1010][1010];
pii pla[1010];
ld dp[1010][1010] = {0}, infd = 1e15;

int main () {
    for (int i = 0; i <= 1005; i++) for (int j = 0; j <= 1005; j++) suma[i][j] = inf;
    for (int i = 0; i <= 1005; i++) suma[i][0] = 0;
    scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; i++) {
        scanf("%d %d", &pla[i].sc, &pla[i].fs);
        if (pla[i].fs == -1) pla[i].fs = inf;
    }
    sort(pla + 1, pla + n + 1);

    //預處理i~n中拿j個a最小的,O(n^2 log n)
    for (int i = 1; i <= n; i++) {
        vector <int> v;
        for (int j = i; j <= n; j++) v.push_back(pla[j].sc);
        sort(v.begin(), v.end());
        int sum = 0;
        for (int j = 0; j < v.size(); j++) sum += v[j], suma[i][j + 1] = sum;
    }

    //要另外枚舉有幾個助手,因為b最小的幾個城市中,如果選擇不講到b,只講到a,那他也該是除"最後的總助手量"而非目前的助手量
    ld ans = suma[1][k];
    for (int bc = 0; bc <= k; bc++) {
        for (int i = 0; i <= 1005; i++) for (int j = 0; j <= 1005; j++) dp[i][j] = infd;
        dp[0][0] = 0;
        for (int i = 1; i <= k; i++) {
            for (int j = 0; j <= min(i, bc); j++) {
                dp[i][j] = min(dp[i][j], dp[i - 1][j] + (ld)pla[i].sc / (bc + 1) );
                if (j and pla[i].fs != inf) dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + (ld)pla[i].fs / j ); 
                if (j == bc) ans = min(ans, dp[i][j] + (ld)suma[i + 1][k - i] / (bc + 1));
            }
        }
    }

    printf("%.9Lf\n", ans);
return 0;}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:30:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for (int j = 0; j < v.size(); j++) sum += v[j], suma[i][j + 1] = sum;
      |                         ~~^~~~~~~~~~
Main.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         scanf("%d %d", &pla[i].sc, &pla[i].fs);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 20316 KB Output is correct
2 Correct 9 ms 20316 KB Output is correct
3 Correct 9 ms 20316 KB Output is correct
4 Correct 10 ms 20316 KB Output is correct
5 Correct 114 ms 20380 KB Output is correct
6 Correct 234 ms 20316 KB Output is correct
7 Correct 456 ms 20312 KB Output is correct
8 Correct 746 ms 20316 KB Output is correct
9 Correct 1133 ms 20380 KB Output is correct
10 Correct 695 ms 20316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 20316 KB Output is correct
2 Correct 9 ms 20316 KB Output is correct
3 Correct 9 ms 20316 KB Output is correct
4 Correct 10 ms 20316 KB Output is correct
5 Correct 114 ms 20380 KB Output is correct
6 Correct 234 ms 20316 KB Output is correct
7 Correct 456 ms 20312 KB Output is correct
8 Correct 746 ms 20316 KB Output is correct
9 Correct 1133 ms 20380 KB Output is correct
10 Correct 695 ms 20316 KB Output is correct
11 Correct 7 ms 20316 KB Output is correct
12 Correct 268 ms 20376 KB Output is correct
13 Correct 281 ms 20380 KB Output is correct
14 Correct 306 ms 20372 KB Output is correct
15 Correct 778 ms 20316 KB Output is correct
16 Correct 770 ms 20372 KB Output is correct
17 Correct 732 ms 20316 KB Output is correct
18 Correct 1364 ms 20376 KB Output is correct
19 Correct 1253 ms 20376 KB Output is correct
20 Correct 1168 ms 20376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 20316 KB Output is correct
2 Correct 9 ms 20316 KB Output is correct
3 Correct 11 ms 20316 KB Output is correct
4 Correct 13 ms 20316 KB Output is correct
5 Correct 18 ms 20316 KB Output is correct
6 Correct 17 ms 20316 KB Output is correct
7 Correct 19 ms 20312 KB Output is correct
8 Correct 14 ms 20312 KB Output is correct
9 Correct 14 ms 20312 KB Output is correct
10 Correct 17 ms 20316 KB Output is correct
11 Correct 13 ms 20312 KB Output is correct
12 Correct 15 ms 20396 KB Output is correct
13 Correct 14 ms 20316 KB Output is correct
14 Correct 15 ms 20312 KB Output is correct
15 Correct 18 ms 20312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 20316 KB Output is correct
2 Correct 9 ms 20316 KB Output is correct
3 Correct 11 ms 20316 KB Output is correct
4 Correct 13 ms 20316 KB Output is correct
5 Correct 18 ms 20316 KB Output is correct
6 Correct 17 ms 20316 KB Output is correct
7 Correct 19 ms 20312 KB Output is correct
8 Correct 14 ms 20312 KB Output is correct
9 Correct 14 ms 20312 KB Output is correct
10 Correct 17 ms 20316 KB Output is correct
11 Correct 13 ms 20312 KB Output is correct
12 Correct 15 ms 20396 KB Output is correct
13 Correct 14 ms 20316 KB Output is correct
14 Correct 15 ms 20312 KB Output is correct
15 Correct 18 ms 20312 KB Output is correct
16 Correct 14 ms 20568 KB Output is correct
17 Correct 24 ms 20312 KB Output is correct
18 Correct 21 ms 20384 KB Output is correct
19 Correct 31 ms 20316 KB Output is correct
20 Correct 31 ms 20312 KB Output is correct
21 Correct 40 ms 20316 KB Output is correct
22 Correct 37 ms 20396 KB Output is correct
23 Correct 41 ms 20368 KB Output is correct
24 Correct 32 ms 20312 KB Output is correct
25 Correct 44 ms 20316 KB Output is correct
26 Correct 42 ms 20316 KB Output is correct
27 Correct 35 ms 20312 KB Output is correct
28 Correct 34 ms 20368 KB Output is correct
29 Correct 30 ms 20316 KB Output is correct
30 Correct 34 ms 20316 KB Output is correct
31 Correct 31 ms 20316 KB Output is correct
32 Correct 34 ms 20316 KB Output is correct
33 Correct 32 ms 20376 KB Output is correct
34 Correct 32 ms 20316 KB Output is correct
35 Correct 32 ms 20372 KB Output is correct
36 Correct 33 ms 20320 KB Output is correct
37 Correct 33 ms 20316 KB Output is correct
38 Correct 35 ms 20376 KB Output is correct
39 Correct 34 ms 20196 KB Output is correct
40 Correct 37 ms 20384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 20316 KB Output is correct
2 Correct 9 ms 20316 KB Output is correct
3 Correct 11 ms 20316 KB Output is correct
4 Correct 13 ms 20316 KB Output is correct
5 Correct 18 ms 20316 KB Output is correct
6 Correct 17 ms 20316 KB Output is correct
7 Correct 19 ms 20312 KB Output is correct
8 Correct 14 ms 20312 KB Output is correct
9 Correct 14 ms 20312 KB Output is correct
10 Correct 17 ms 20316 KB Output is correct
11 Correct 13 ms 20312 KB Output is correct
12 Correct 15 ms 20396 KB Output is correct
13 Correct 14 ms 20316 KB Output is correct
14 Correct 15 ms 20312 KB Output is correct
15 Correct 18 ms 20312 KB Output is correct
16 Correct 14 ms 20568 KB Output is correct
17 Correct 24 ms 20312 KB Output is correct
18 Correct 21 ms 20384 KB Output is correct
19 Correct 31 ms 20316 KB Output is correct
20 Correct 31 ms 20312 KB Output is correct
21 Correct 40 ms 20316 KB Output is correct
22 Correct 37 ms 20396 KB Output is correct
23 Correct 41 ms 20368 KB Output is correct
24 Correct 32 ms 20312 KB Output is correct
25 Correct 44 ms 20316 KB Output is correct
26 Correct 42 ms 20316 KB Output is correct
27 Correct 35 ms 20312 KB Output is correct
28 Correct 34 ms 20368 KB Output is correct
29 Correct 30 ms 20316 KB Output is correct
30 Correct 34 ms 20316 KB Output is correct
31 Correct 31 ms 20316 KB Output is correct
32 Correct 34 ms 20316 KB Output is correct
33 Correct 32 ms 20376 KB Output is correct
34 Correct 32 ms 20316 KB Output is correct
35 Correct 32 ms 20372 KB Output is correct
36 Correct 33 ms 20320 KB Output is correct
37 Correct 33 ms 20316 KB Output is correct
38 Correct 35 ms 20376 KB Output is correct
39 Correct 34 ms 20196 KB Output is correct
40 Correct 37 ms 20384 KB Output is correct
41 Correct 38 ms 20452 KB Output is correct
42 Correct 34 ms 20392 KB Output is correct
43 Correct 70 ms 20392 KB Output is correct
44 Correct 70 ms 20316 KB Output is correct
45 Correct 101 ms 20316 KB Output is correct
46 Correct 99 ms 20348 KB Output is correct
47 Correct 140 ms 20384 KB Output is correct
48 Correct 135 ms 20388 KB Output is correct
49 Correct 161 ms 20376 KB Output is correct
50 Correct 168 ms 20372 KB Output is correct
51 Correct 215 ms 20368 KB Output is correct
52 Correct 203 ms 20316 KB Output is correct
53 Correct 140 ms 20316 KB Output is correct
54 Correct 137 ms 20316 KB Output is correct
55 Correct 129 ms 20196 KB Output is correct
56 Correct 134 ms 20380 KB Output is correct
57 Correct 143 ms 20368 KB Output is correct
58 Correct 132 ms 20368 KB Output is correct
59 Correct 145 ms 20368 KB Output is correct
60 Correct 131 ms 20372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1373 ms 20376 KB Output is correct
2 Correct 1409 ms 20376 KB Output is correct
3 Correct 1359 ms 20384 KB Output is correct
4 Correct 1369 ms 20316 KB Output is correct
5 Correct 1383 ms 20380 KB Output is correct
6 Correct 1394 ms 20396 KB Output is correct
7 Correct 1356 ms 20376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 20316 KB Output is correct
2 Correct 9 ms 20316 KB Output is correct
3 Correct 9 ms 20316 KB Output is correct
4 Correct 10 ms 20316 KB Output is correct
5 Correct 114 ms 20380 KB Output is correct
6 Correct 234 ms 20316 KB Output is correct
7 Correct 456 ms 20312 KB Output is correct
8 Correct 746 ms 20316 KB Output is correct
9 Correct 1133 ms 20380 KB Output is correct
10 Correct 695 ms 20316 KB Output is correct
11 Correct 7 ms 20316 KB Output is correct
12 Correct 268 ms 20376 KB Output is correct
13 Correct 281 ms 20380 KB Output is correct
14 Correct 306 ms 20372 KB Output is correct
15 Correct 778 ms 20316 KB Output is correct
16 Correct 770 ms 20372 KB Output is correct
17 Correct 732 ms 20316 KB Output is correct
18 Correct 1364 ms 20376 KB Output is correct
19 Correct 1253 ms 20376 KB Output is correct
20 Correct 1168 ms 20376 KB Output is correct
21 Correct 7 ms 20316 KB Output is correct
22 Correct 9 ms 20316 KB Output is correct
23 Correct 11 ms 20316 KB Output is correct
24 Correct 13 ms 20316 KB Output is correct
25 Correct 18 ms 20316 KB Output is correct
26 Correct 17 ms 20316 KB Output is correct
27 Correct 19 ms 20312 KB Output is correct
28 Correct 14 ms 20312 KB Output is correct
29 Correct 14 ms 20312 KB Output is correct
30 Correct 17 ms 20316 KB Output is correct
31 Correct 13 ms 20312 KB Output is correct
32 Correct 15 ms 20396 KB Output is correct
33 Correct 14 ms 20316 KB Output is correct
34 Correct 15 ms 20312 KB Output is correct
35 Correct 18 ms 20312 KB Output is correct
36 Correct 14 ms 20568 KB Output is correct
37 Correct 24 ms 20312 KB Output is correct
38 Correct 21 ms 20384 KB Output is correct
39 Correct 31 ms 20316 KB Output is correct
40 Correct 31 ms 20312 KB Output is correct
41 Correct 40 ms 20316 KB Output is correct
42 Correct 37 ms 20396 KB Output is correct
43 Correct 41 ms 20368 KB Output is correct
44 Correct 32 ms 20312 KB Output is correct
45 Correct 44 ms 20316 KB Output is correct
46 Correct 42 ms 20316 KB Output is correct
47 Correct 35 ms 20312 KB Output is correct
48 Correct 34 ms 20368 KB Output is correct
49 Correct 30 ms 20316 KB Output is correct
50 Correct 34 ms 20316 KB Output is correct
51 Correct 31 ms 20316 KB Output is correct
52 Correct 34 ms 20316 KB Output is correct
53 Correct 32 ms 20376 KB Output is correct
54 Correct 32 ms 20316 KB Output is correct
55 Correct 32 ms 20372 KB Output is correct
56 Correct 33 ms 20320 KB Output is correct
57 Correct 33 ms 20316 KB Output is correct
58 Correct 35 ms 20376 KB Output is correct
59 Correct 34 ms 20196 KB Output is correct
60 Correct 37 ms 20384 KB Output is correct
61 Correct 38 ms 20452 KB Output is correct
62 Correct 34 ms 20392 KB Output is correct
63 Correct 70 ms 20392 KB Output is correct
64 Correct 70 ms 20316 KB Output is correct
65 Correct 101 ms 20316 KB Output is correct
66 Correct 99 ms 20348 KB Output is correct
67 Correct 140 ms 20384 KB Output is correct
68 Correct 135 ms 20388 KB Output is correct
69 Correct 161 ms 20376 KB Output is correct
70 Correct 168 ms 20372 KB Output is correct
71 Correct 215 ms 20368 KB Output is correct
72 Correct 203 ms 20316 KB Output is correct
73 Correct 140 ms 20316 KB Output is correct
74 Correct 137 ms 20316 KB Output is correct
75 Correct 129 ms 20196 KB Output is correct
76 Correct 134 ms 20380 KB Output is correct
77 Correct 143 ms 20368 KB Output is correct
78 Correct 132 ms 20368 KB Output is correct
79 Correct 145 ms 20368 KB Output is correct
80 Correct 131 ms 20372 KB Output is correct
81 Correct 1373 ms 20376 KB Output is correct
82 Correct 1409 ms 20376 KB Output is correct
83 Correct 1359 ms 20384 KB Output is correct
84 Correct 1369 ms 20316 KB Output is correct
85 Correct 1383 ms 20380 KB Output is correct
86 Correct 1394 ms 20396 KB Output is correct
87 Correct 1356 ms 20376 KB Output is correct
88 Correct 117 ms 20368 KB Output is correct
89 Correct 104 ms 20376 KB Output is correct
90 Correct 281 ms 20312 KB Output is correct
91 Correct 259 ms 20316 KB Output is correct
92 Correct 566 ms 20372 KB Output is correct
93 Correct 608 ms 20376 KB Output is correct
94 Correct 908 ms 20372 KB Output is correct
95 Correct 925 ms 20376 KB Output is correct
96 Correct 1212 ms 20372 KB Output is correct
97 Correct 1229 ms 20376 KB Output is correct
98 Correct 813 ms 20312 KB Output is correct
99 Correct 825 ms 20372 KB Output is correct
100 Correct 817 ms 20376 KB Output is correct
101 Correct 794 ms 20376 KB Output is correct
102 Correct 812 ms 20372 KB Output is correct
103 Correct 787 ms 20560 KB Output is correct
104 Correct 809 ms 20380 KB Output is correct
105 Correct 787 ms 20376 KB Output is correct