Submission #636963

# Submission time Handle Problem Language Result Execution time Memory
636963 2022-08-30T19:30:03 Z danikoynov Let's Win the Election (JOI22_ho_t3) C++14
67 / 100
183 ms 10964 KB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 510, smalln = 110;
struct city
{
    int a, b, idx;
}c[maxn], ct[maxn];
int n, k, used[maxn];

bool cmpa(city c1, city c2)
{
    return c1.a < c2.a;
}
bool cmpb(city c1, city c2)
{
    if (c1.b != -1 && c2.b != -1)
        return c1.b < c2.b;
    if (c1.b != -1)
        return true;
    if (c2.b != -1)
        return false;
    return c1.idx < c2.idx;
}

double dp[smalln][smalln][smalln], fp[maxn][maxn];
/// dp[i][j][f] - smallest time up to the i-th city using j votes and f collaborators
void solve()
{
    cin >> n >> k;
    int col = 0;
    for (int i = 1; i <= n; i ++)
    {
        cin >> c[i].a >> c[i].b;
        if (c[i].b != -1)
            col ++;
        c[i].idx = i;
        ct[i] = c[i];
    }

    sort(c + 1, c + n + 1, cmpb);
    double ans = 1e18;
    if (k != n)
    {


    for (int goal = 0; goal <= min(k, col); goal ++)
    {
        for (int i = 0; i <= n; i ++)
            for (int j = 0; j <= k; j ++)
            for (int f = 0; f <= goal; f ++)
            dp[i][j][f] = 1e18;

        dp[0][0][0] = 0.0;
        for (int i = 1; i <= n; i ++)
            for (int j = 0; j <= k; j ++)
            for (int f = 0; f <= goal; f ++)
        {
            dp[i][j][f] = dp[i - 1][j][f];
            if (j >= 1)
            {
                dp[i][j][f] = min(dp[i][j][f], dp[i - 1][j - 1][f] + c[i].a / (double)(goal + 1.0));
            }
            if (f >= 1 && c[i].b != -1 && j >= 1)
            {
                dp[i][j][f] = min(dp[i][j][f], dp[i - 1][j - 1][f - 1] + c[i].b / (double)(f));
            }
        }

        /**cout << "--------- " << goal << " -------------------" << endl;
        for (int i = 1; i <= n; i ++)
            for (int j = 0; j <= k; j ++)
            for (int f = 0; f <= goal; f ++)
            cout << i << " " << j << " " << f << " " << dp[i][j][f] << endl;*/

        ans = min(ans, dp[n][k][goal]);
    }
    }
    else

    {
for (int goal = 0; goal <= min(k, col); goal ++)
    {
        for (int i = 0; i <= n; i ++)
            for (int f = 0; f <= goal; f ++)
            fp[i][f] = 1e18;

        fp[0][0] = 0.0;
        for (int i = 1; i <= n; i ++)
            for (int f = 0; f <= goal; f ++)
        {
                fp[i][f] = min(fp[i][f], fp[i - 1][f] + c[i].a / (double)(goal + 1.0));

            if (f >= 1 && c[i].b != -1)
            {
                fp[i][f] = min(fp[i][f], fp[i - 1][f - 1] + c[i].b / (double)(f));
            }
        }

        /**cout << "--------- " << goal << " -------------------" << endl;
        for (int i = 1; i <= n; i ++)
            for (int j = 0; j <= k; j ++)
            for (int f = 0; f <= goal; f ++)
            cout << i << " " << j << " " << f << " " << fp[i][j][f] << endl;*/

        ans = min(ans, fp[n][goal]);
    }
    }
    printf("%0.6f\n", ans);
}

int main()
{
    solve();
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Runtime error 7 ms 10964 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Runtime error 7 ms 10964 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 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 1 ms 308 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 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 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 0 ms 340 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 308 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 1 ms 308 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 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 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 0 ms 340 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 308 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 468 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 560 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 596 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 560 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 ms 596 KB Output is correct
35 Correct 1 ms 596 KB Output is correct
36 Correct 1 ms 596 KB Output is correct
37 Correct 1 ms 596 KB Output is correct
38 Correct 1 ms 596 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 1 ms 596 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 1 ms 308 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 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 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 0 ms 340 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 308 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 468 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 560 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 596 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 560 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 ms 596 KB Output is correct
35 Correct 1 ms 596 KB Output is correct
36 Correct 1 ms 596 KB Output is correct
37 Correct 1 ms 596 KB Output is correct
38 Correct 1 ms 596 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 1 ms 596 KB Output is correct
41 Correct 3 ms 2004 KB Output is correct
42 Correct 2 ms 2004 KB Output is correct
43 Correct 10 ms 3248 KB Output is correct
44 Correct 8 ms 3352 KB Output is correct
45 Correct 32 ms 5100 KB Output is correct
46 Correct 30 ms 5096 KB Output is correct
47 Correct 74 ms 6392 KB Output is correct
48 Correct 66 ms 6604 KB Output is correct
49 Correct 124 ms 7716 KB Output is correct
50 Correct 112 ms 7696 KB Output is correct
51 Correct 2 ms 696 KB Output is correct
52 Correct 2 ms 724 KB Output is correct
53 Correct 75 ms 6412 KB Output is correct
54 Correct 75 ms 6400 KB Output is correct
55 Correct 68 ms 6404 KB Output is correct
56 Correct 68 ms 6528 KB Output is correct
57 Correct 68 ms 6400 KB Output is correct
58 Correct 68 ms 6404 KB Output is correct
59 Correct 66 ms 6324 KB Output is correct
60 Correct 87 ms 6408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 183 ms 2300 KB Output is correct
2 Correct 153 ms 2296 KB Output is correct
3 Correct 151 ms 2304 KB Output is correct
4 Correct 161 ms 2296 KB Output is correct
5 Correct 170 ms 2348 KB Output is correct
6 Correct 159 ms 2304 KB Output is correct
7 Correct 155 ms 2380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Runtime error 7 ms 10964 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -