답안 #914913

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
914913 2024-01-22T21:21:42 Z andrei_iorgulescu Let's Win the Election (JOI22_ho_t3) C++14
100 / 100
1220 ms 4436 KB
#include <bits/stdc++.h>

using namespace std;
using ld = long double;

#define int long long

int n,k;
ld m;
pair<ld,ld> a[505];
ld dp[505][505];

ld solve()
{
    ///daca sortez dupa b, mi-e foarte ez
    ///dp[i][j] = costul minim sa ajung la omul i sa fi luat j a-uri
    ///c = min(m + 1,i - j + 1)
    ///dp[i][j] -> dp[i + 1][j] de cost b[i + 1] / c ofc daca n-am luat prea multe b-uri
    ///dp[i][j] -> dp[i + 1][j + 1] de cost a[i + 1] / m
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= n; j++)
            dp[i][j] = 1e9;
    }
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            ld c = i - j;
            //if (i - j <= m)
            if (i - j <= m and i - j != 0)
                dp[i][j] = min(dp[i][j],dp[i - 1][j] + a[i].first / c);
            else if (i - j > m)
                dp[i][j] = min(dp[i][j],dp[i - 1][j]);
            if (j >= 1)
                dp[i][j] = min(dp[i][j],dp[i - 1][j - 1] + a[i].second / (m + 1));
            //cout << i << ' ' << j << ' ' << dp[i][j] << endl;
        }
    }
    //cout << dp[n][(int)(k - m)] << endl;
    return dp[n][(int)(k - m)];
}

ld solve_normal()
{
    ///fuckkkk n-a mers greedy-ul :facepalm:
    sort(a + 1,a + n + 1);
    ld ans = 1e6;
    for (m = 0; m < k; m++)
        ans = min(ans,solve());
    return ans;
}

/*ld solve_brut()
{
    ld ans = 1e6;
    vector<int>ids;
    for (int i = 1; i <= n; i++)
        ids.push_back(i);
    do
    {
        for (ld m = 1; m <= k; m++)
        {
            ld cur = 0;
            for (ld j = 1; j < m; j++)
                cur += b[ids[j - 1]] / j;
            for (ld j = m; j <= k; j++)
                cur += a[ids[j - 1]] / m;
            ans = min(ans,cur);
        }
    }while(next_permutation(ids.begin(),ids.end()));
    return ans;
}*/

bool generez_teste = false;

void citire()
{
    if (generez_teste == false)
    {
        cin >> n >> k;
        for (int i = 1; i <= n; i++)
            cin >> a[i].second >> a[i].first;
        for (int i = 1; i <= n; i++)
            if (a[i].first == -1)
                a[i].first = 1e9;
    }
    /*else
    {
        n = 3;
        k = 2;
        for (int i = 1; i <= n; i++)
        {
            a[i] = 1 + rand() % 9;
            b[i] = a[i] + rand() % 10;
            if (b[i] - a[i] == 9)
                b[i] = -1;
            if (b[i] == -1)
                b[i] = 1e9;
        }
    }*/
}

signed main()
{
    cout << setprecision(5) << fixed;
    citire();
    cout << solve_normal();
    return 0;
    /*srand(0);
    ld ans_normal,ans_brut;
    while (true)
    {
        citire();
        ans_normal = solve_normal();
        ans_brut = solve_brut();
        if (abs(ans_normal - ans_brut) >= 0.00001d)
        {
            for (int i = 1; i <= n; i++)
                cout << a[i] << ' ' << b[i] << endl;
            break;
        }
    }
    cout << setprecision(5) << fixed;
    //cout << ans_normal << ' ' << ans_brut;
    return 0;*/
}

/**
3
3
9 9
3 6
7 14
**/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 122 ms 4400 KB Output is correct
6 Correct 302 ms 4404 KB Output is correct
7 Correct 595 ms 4436 KB Output is correct
8 Correct 903 ms 4436 KB Output is correct
9 Correct 1214 ms 4404 KB Output is correct
10 Correct 843 ms 4396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 122 ms 4400 KB Output is correct
6 Correct 302 ms 4404 KB Output is correct
7 Correct 595 ms 4436 KB Output is correct
8 Correct 903 ms 4436 KB Output is correct
9 Correct 1214 ms 4404 KB Output is correct
10 Correct 843 ms 4396 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 355 ms 4188 KB Output is correct
13 Correct 355 ms 4184 KB Output is correct
14 Correct 355 ms 4400 KB Output is correct
15 Correct 843 ms 4432 KB Output is correct
16 Correct 845 ms 4400 KB Output is correct
17 Correct 842 ms 4400 KB Output is correct
18 Correct 1209 ms 4436 KB Output is correct
19 Correct 1220 ms 4400 KB Output is correct
20 Correct 1209 ms 4416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 440 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 440 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 3 ms 2636 KB Output is correct
42 Correct 2 ms 2396 KB Output is correct
43 Correct 4 ms 2644 KB Output is correct
44 Correct 4 ms 2396 KB Output is correct
45 Correct 6 ms 2396 KB Output is correct
46 Correct 6 ms 2396 KB Output is correct
47 Correct 7 ms 2636 KB Output is correct
48 Correct 7 ms 2396 KB Output is correct
49 Correct 9 ms 2396 KB Output is correct
50 Correct 9 ms 2392 KB Output is correct
51 Correct 11 ms 2396 KB Output is correct
52 Correct 11 ms 2396 KB Output is correct
53 Correct 8 ms 2632 KB Output is correct
54 Correct 8 ms 2396 KB Output is correct
55 Correct 7 ms 2392 KB Output is correct
56 Correct 7 ms 2396 KB Output is correct
57 Correct 7 ms 2396 KB Output is correct
58 Correct 8 ms 2396 KB Output is correct
59 Correct 7 ms 2396 KB Output is correct
60 Correct 7 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1213 ms 4436 KB Output is correct
2 Correct 1214 ms 4436 KB Output is correct
3 Correct 1212 ms 4396 KB Output is correct
4 Correct 1216 ms 4436 KB Output is correct
5 Correct 1220 ms 4436 KB Output is correct
6 Correct 1210 ms 4404 KB Output is correct
7 Correct 1208 ms 4400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 122 ms 4400 KB Output is correct
6 Correct 302 ms 4404 KB Output is correct
7 Correct 595 ms 4436 KB Output is correct
8 Correct 903 ms 4436 KB Output is correct
9 Correct 1214 ms 4404 KB Output is correct
10 Correct 843 ms 4396 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 355 ms 4188 KB Output is correct
13 Correct 355 ms 4184 KB Output is correct
14 Correct 355 ms 4400 KB Output is correct
15 Correct 843 ms 4432 KB Output is correct
16 Correct 845 ms 4400 KB Output is correct
17 Correct 842 ms 4400 KB Output is correct
18 Correct 1209 ms 4436 KB Output is correct
19 Correct 1220 ms 4400 KB Output is correct
20 Correct 1209 ms 4416 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 440 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 344 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 1 ms 344 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 3 ms 2636 KB Output is correct
62 Correct 2 ms 2396 KB Output is correct
63 Correct 4 ms 2644 KB Output is correct
64 Correct 4 ms 2396 KB Output is correct
65 Correct 6 ms 2396 KB Output is correct
66 Correct 6 ms 2396 KB Output is correct
67 Correct 7 ms 2636 KB Output is correct
68 Correct 7 ms 2396 KB Output is correct
69 Correct 9 ms 2396 KB Output is correct
70 Correct 9 ms 2392 KB Output is correct
71 Correct 11 ms 2396 KB Output is correct
72 Correct 11 ms 2396 KB Output is correct
73 Correct 8 ms 2632 KB Output is correct
74 Correct 8 ms 2396 KB Output is correct
75 Correct 7 ms 2392 KB Output is correct
76 Correct 7 ms 2396 KB Output is correct
77 Correct 7 ms 2396 KB Output is correct
78 Correct 8 ms 2396 KB Output is correct
79 Correct 7 ms 2396 KB Output is correct
80 Correct 7 ms 2636 KB Output is correct
81 Correct 1213 ms 4436 KB Output is correct
82 Correct 1214 ms 4436 KB Output is correct
83 Correct 1212 ms 4396 KB Output is correct
84 Correct 1216 ms 4436 KB Output is correct
85 Correct 1220 ms 4436 KB Output is correct
86 Correct 1210 ms 4404 KB Output is correct
87 Correct 1208 ms 4400 KB Output is correct
88 Correct 120 ms 4188 KB Output is correct
89 Correct 119 ms 4404 KB Output is correct
90 Correct 301 ms 4404 KB Output is correct
91 Correct 300 ms 4436 KB Output is correct
92 Correct 595 ms 4404 KB Output is correct
93 Correct 600 ms 4184 KB Output is correct
94 Correct 905 ms 4184 KB Output is correct
95 Correct 902 ms 4404 KB Output is correct
96 Correct 1087 ms 4400 KB Output is correct
97 Correct 1092 ms 4400 KB Output is correct
98 Correct 846 ms 4432 KB Output is correct
99 Correct 843 ms 4404 KB Output is correct
100 Correct 847 ms 4400 KB Output is correct
101 Correct 846 ms 4436 KB Output is correct
102 Correct 844 ms 4404 KB Output is correct
103 Correct 852 ms 4436 KB Output is correct
104 Correct 842 ms 4416 KB Output is correct
105 Correct 842 ms 4436 KB Output is correct