답안 #914915

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
914915 2024-01-22T21:26:24 Z andrei_iorgulescu Let's Win the Election (JOI22_ho_t3) C++14
100 / 100
53 ms 4440 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 slv(ld x)
{
    m = x;
    return solve();
}

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());
    int st = 0,pas = 1 << 8;
    while (pas != 0)
    {
        if (st + pas < k and slv(st + pas - 1) > slv(st + pas))
            st += pas;
        pas /= 2;
    }
    ans = slv(st);
    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 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 32 ms 4420 KB Output is correct
6 Correct 37 ms 4188 KB Output is correct
7 Correct 42 ms 4188 KB Output is correct
8 Correct 51 ms 4436 KB Output is correct
9 Correct 46 ms 4188 KB Output is correct
10 Correct 52 ms 4188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 32 ms 4420 KB Output is correct
6 Correct 37 ms 4188 KB Output is correct
7 Correct 42 ms 4188 KB Output is correct
8 Correct 51 ms 4436 KB Output is correct
9 Correct 46 ms 4188 KB Output is correct
10 Correct 52 ms 4188 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 23 ms 4188 KB Output is correct
13 Correct 42 ms 4188 KB Output is correct
14 Correct 42 ms 4188 KB Output is correct
15 Correct 37 ms 4436 KB Output is correct
16 Correct 48 ms 4188 KB Output is correct
17 Correct 47 ms 4184 KB Output is correct
18 Correct 39 ms 4188 KB Output is correct
19 Correct 49 ms 4184 KB Output is correct
20 Correct 47 ms 4188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 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 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 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 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 344 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 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 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 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 344 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 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 2 ms 2396 KB Output is correct
42 Correct 2 ms 2392 KB Output is correct
43 Correct 3 ms 2804 KB Output is correct
44 Correct 2 ms 2396 KB Output is correct
45 Correct 2 ms 2396 KB Output is correct
46 Correct 2 ms 2396 KB Output is correct
47 Correct 2 ms 2396 KB Output is correct
48 Correct 2 ms 2396 KB Output is correct
49 Correct 2 ms 2396 KB Output is correct
50 Correct 2 ms 2396 KB Output is correct
51 Correct 2 ms 2396 KB Output is correct
52 Correct 2 ms 2396 KB Output is correct
53 Correct 2 ms 2392 KB Output is correct
54 Correct 2 ms 2396 KB Output is correct
55 Correct 2 ms 2396 KB Output is correct
56 Correct 3 ms 2396 KB Output is correct
57 Correct 2 ms 2396 KB Output is correct
58 Correct 2 ms 2396 KB Output is correct
59 Correct 2 ms 2652 KB Output is correct
60 Correct 2 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 4184 KB Output is correct
2 Correct 48 ms 4400 KB Output is correct
3 Correct 53 ms 4192 KB Output is correct
4 Correct 48 ms 4188 KB Output is correct
5 Correct 52 ms 4440 KB Output is correct
6 Correct 48 ms 4400 KB Output is correct
7 Correct 49 ms 4196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 32 ms 4420 KB Output is correct
6 Correct 37 ms 4188 KB Output is correct
7 Correct 42 ms 4188 KB Output is correct
8 Correct 51 ms 4436 KB Output is correct
9 Correct 46 ms 4188 KB Output is correct
10 Correct 52 ms 4188 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 23 ms 4188 KB Output is correct
13 Correct 42 ms 4188 KB Output is correct
14 Correct 42 ms 4188 KB Output is correct
15 Correct 37 ms 4436 KB Output is correct
16 Correct 48 ms 4188 KB Output is correct
17 Correct 47 ms 4184 KB Output is correct
18 Correct 39 ms 4188 KB Output is correct
19 Correct 49 ms 4184 KB Output is correct
20 Correct 47 ms 4188 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 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 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 600 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 1 ms 344 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 2 ms 2396 KB Output is correct
62 Correct 2 ms 2392 KB Output is correct
63 Correct 3 ms 2804 KB Output is correct
64 Correct 2 ms 2396 KB Output is correct
65 Correct 2 ms 2396 KB Output is correct
66 Correct 2 ms 2396 KB Output is correct
67 Correct 2 ms 2396 KB Output is correct
68 Correct 2 ms 2396 KB Output is correct
69 Correct 2 ms 2396 KB Output is correct
70 Correct 2 ms 2396 KB Output is correct
71 Correct 2 ms 2396 KB Output is correct
72 Correct 2 ms 2396 KB Output is correct
73 Correct 2 ms 2392 KB Output is correct
74 Correct 2 ms 2396 KB Output is correct
75 Correct 2 ms 2396 KB Output is correct
76 Correct 3 ms 2396 KB Output is correct
77 Correct 2 ms 2396 KB Output is correct
78 Correct 2 ms 2396 KB Output is correct
79 Correct 2 ms 2652 KB Output is correct
80 Correct 2 ms 2396 KB Output is correct
81 Correct 48 ms 4184 KB Output is correct
82 Correct 48 ms 4400 KB Output is correct
83 Correct 53 ms 4192 KB Output is correct
84 Correct 48 ms 4188 KB Output is correct
85 Correct 52 ms 4440 KB Output is correct
86 Correct 48 ms 4400 KB Output is correct
87 Correct 49 ms 4196 KB Output is correct
88 Correct 32 ms 4372 KB Output is correct
89 Correct 32 ms 4304 KB Output is correct
90 Correct 37 ms 4188 KB Output is correct
91 Correct 39 ms 4184 KB Output is correct
92 Correct 42 ms 4184 KB Output is correct
93 Correct 43 ms 4184 KB Output is correct
94 Correct 47 ms 4188 KB Output is correct
95 Correct 43 ms 4192 KB Output is correct
96 Correct 48 ms 4396 KB Output is correct
97 Correct 49 ms 4184 KB Output is correct
98 Correct 47 ms 4400 KB Output is correct
99 Correct 47 ms 4188 KB Output is correct
100 Correct 47 ms 4188 KB Output is correct
101 Correct 48 ms 4184 KB Output is correct
102 Correct 43 ms 4188 KB Output is correct
103 Correct 44 ms 4188 KB Output is correct
104 Correct 48 ms 4188 KB Output is correct
105 Correct 46 ms 4188 KB Output is correct