Submission #745720

# Submission time Handle Problem Language Result Execution time Memory
745720 2023-05-21T04:38:52 Z nguyentunglam Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
786 ms 5452 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 510;
pair<int, int> a[N];
int g[N][N];
long double f[N][N];
int main() {
    #define task ""
    cin.tie(0) -> sync_with_stdio(0);
    if (fopen ("task.inp", "r")) {
        freopen ("task.inp", "r", stdin);
        freopen ("task.out", "w", stdout);
    }
    if (fopen (task".inp", "r")) {
        freopen (task".inp", "r", stdin);
        freopen (task".out", "w", stdout);
    }
    int n, k; cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        cin >> a[i].fi >> a[i].se;
        if (a[i].se == -1) a[i].se = 1e9;
    }
    sort(a + 1, a + n + 1, [] (const ii &x, const ii &y) {
         if (x.se != y.se) return x.se < y.se;
         return x.fi < y.fi;
         });
     long double res = 1e9;
     for(int j = 1; j <= n; j++) g[n + 1][j] = 1e9, f[0][j] = 1e9;
     for(int i = n; i >= 1; i--) {
        g[i][0] = g[i + 1][0];
        for(int j = 1; j <= n; j++) g[i][j] = min(g[i + 1][j], g[i + 1][j - 1] + a[i].fi);
     }
     for(int cnt = 0; cnt <= k; cnt++) {
        for(int i = 1; i <= n; i++) {
            f[i][0] = f[i - 1][0] + 1.0 * a[i].fi / (cnt + 1);
            for(int j = 1; j <= n; j++) {
                f[i][j] = min(f[i - 1][j] + 1.0 * a[i].fi / (cnt + 1), f[i - 1][j - 1] + 1.0 * a[i].se / j);
            }
        }
        for(int i = 0; i <= k; i++) {
            res = min(res, f[i][cnt] + 1.0 * g[i + 1][k - i] / (cnt + 1));
        }
     }
     cout << fixed << setprecision(9) << res;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:15:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:16:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:19:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:20:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 71 ms 5332 KB Output is correct
6 Correct 171 ms 5332 KB Output is correct
7 Correct 335 ms 5336 KB Output is correct
8 Correct 496 ms 5332 KB Output is correct
9 Correct 662 ms 5332 KB Output is correct
10 Correct 461 ms 5332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 71 ms 5332 KB Output is correct
6 Correct 171 ms 5332 KB Output is correct
7 Correct 335 ms 5336 KB Output is correct
8 Correct 496 ms 5332 KB Output is correct
9 Correct 662 ms 5332 KB Output is correct
10 Correct 461 ms 5332 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 205 ms 5332 KB Output is correct
13 Correct 201 ms 5336 KB Output is correct
14 Correct 248 ms 5332 KB Output is correct
15 Correct 478 ms 5452 KB Output is correct
16 Correct 470 ms 5332 KB Output is correct
17 Correct 469 ms 5332 KB Output is correct
18 Correct 695 ms 5332 KB Output is correct
19 Correct 706 ms 5332 KB Output is correct
20 Correct 703 ms 5332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 456 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 460 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 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 456 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 460 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 340 KB Output is correct
41 Correct 2 ms 1108 KB Output is correct
42 Correct 2 ms 1108 KB Output is correct
43 Correct 3 ms 1108 KB Output is correct
44 Correct 2 ms 1108 KB Output is correct
45 Correct 4 ms 1108 KB Output is correct
46 Correct 4 ms 1108 KB Output is correct
47 Correct 5 ms 1096 KB Output is correct
48 Correct 5 ms 1108 KB Output is correct
49 Correct 5 ms 1108 KB Output is correct
50 Correct 9 ms 1100 KB Output is correct
51 Correct 8 ms 1148 KB Output is correct
52 Correct 6 ms 1108 KB Output is correct
53 Correct 5 ms 1108 KB Output is correct
54 Correct 4 ms 1108 KB Output is correct
55 Correct 4 ms 1108 KB Output is correct
56 Correct 5 ms 1096 KB Output is correct
57 Correct 4 ms 1104 KB Output is correct
58 Correct 4 ms 1108 KB Output is correct
59 Correct 5 ms 1108 KB Output is correct
60 Correct 4 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 786 ms 5320 KB Output is correct
2 Correct 739 ms 5332 KB Output is correct
3 Correct 688 ms 5332 KB Output is correct
4 Correct 716 ms 5332 KB Output is correct
5 Correct 695 ms 5332 KB Output is correct
6 Correct 693 ms 5332 KB Output is correct
7 Correct 780 ms 5332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 71 ms 5332 KB Output is correct
6 Correct 171 ms 5332 KB Output is correct
7 Correct 335 ms 5336 KB Output is correct
8 Correct 496 ms 5332 KB Output is correct
9 Correct 662 ms 5332 KB Output is correct
10 Correct 461 ms 5332 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 205 ms 5332 KB Output is correct
13 Correct 201 ms 5336 KB Output is correct
14 Correct 248 ms 5332 KB Output is correct
15 Correct 478 ms 5452 KB Output is correct
16 Correct 470 ms 5332 KB Output is correct
17 Correct 469 ms 5332 KB Output is correct
18 Correct 695 ms 5332 KB Output is correct
19 Correct 706 ms 5332 KB Output is correct
20 Correct 703 ms 5332 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 328 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 328 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 460 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 456 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 460 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 2 ms 1108 KB Output is correct
62 Correct 2 ms 1108 KB Output is correct
63 Correct 3 ms 1108 KB Output is correct
64 Correct 2 ms 1108 KB Output is correct
65 Correct 4 ms 1108 KB Output is correct
66 Correct 4 ms 1108 KB Output is correct
67 Correct 5 ms 1096 KB Output is correct
68 Correct 5 ms 1108 KB Output is correct
69 Correct 5 ms 1108 KB Output is correct
70 Correct 9 ms 1100 KB Output is correct
71 Correct 8 ms 1148 KB Output is correct
72 Correct 6 ms 1108 KB Output is correct
73 Correct 5 ms 1108 KB Output is correct
74 Correct 4 ms 1108 KB Output is correct
75 Correct 4 ms 1108 KB Output is correct
76 Correct 5 ms 1096 KB Output is correct
77 Correct 4 ms 1104 KB Output is correct
78 Correct 4 ms 1108 KB Output is correct
79 Correct 5 ms 1108 KB Output is correct
80 Correct 4 ms 1108 KB Output is correct
81 Correct 786 ms 5320 KB Output is correct
82 Correct 739 ms 5332 KB Output is correct
83 Correct 688 ms 5332 KB Output is correct
84 Correct 716 ms 5332 KB Output is correct
85 Correct 695 ms 5332 KB Output is correct
86 Correct 693 ms 5332 KB Output is correct
87 Correct 780 ms 5332 KB Output is correct
88 Correct 77 ms 5332 KB Output is correct
89 Correct 78 ms 5324 KB Output is correct
90 Correct 182 ms 5332 KB Output is correct
91 Correct 172 ms 5332 KB Output is correct
92 Correct 337 ms 5332 KB Output is correct
93 Correct 360 ms 5332 KB Output is correct
94 Correct 516 ms 5332 KB Output is correct
95 Correct 540 ms 5452 KB Output is correct
96 Correct 610 ms 5332 KB Output is correct
97 Correct 624 ms 5332 KB Output is correct
98 Correct 473 ms 5332 KB Output is correct
99 Correct 496 ms 5332 KB Output is correct
100 Correct 500 ms 5332 KB Output is correct
101 Correct 478 ms 5332 KB Output is correct
102 Correct 474 ms 5332 KB Output is correct
103 Correct 538 ms 5332 KB Output is correct
104 Correct 467 ms 5336 KB Output is correct
105 Correct 477 ms 5332 KB Output is correct