답안 #636965

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
636965 2022-08-30T19:41:38 Z danikoynov Let's Win the Election (JOI22_ho_t3) C++14
100 / 100
518 ms 4436 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[maxn][maxn], 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;

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));
            }
        }


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

        for (int i = 0; i <= k; i ++)
        {
            double sum = fp[i][goal] + dp[i + 1][k - i];
            if (sum < ans)
                ans = sum;
        }
        ///ans = min(ans, fp[n][goal]);
    }

    printf("%0.6f\n", ans);
}

int main()
{
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 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 2 ms 4308 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4308 KB Output is correct
8 Correct 2 ms 4276 KB Output is correct
9 Correct 2 ms 4308 KB Output is correct
10 Correct 2 ms 4308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 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 2 ms 4308 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4308 KB Output is correct
8 Correct 2 ms 4276 KB Output is correct
9 Correct 2 ms 4308 KB Output is correct
10 Correct 2 ms 4308 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 48 ms 4308 KB Output is correct
13 Correct 43 ms 4308 KB Output is correct
14 Correct 27 ms 4308 KB Output is correct
15 Correct 233 ms 4436 KB Output is correct
16 Correct 244 ms 4300 KB Output is correct
17 Correct 47 ms 4316 KB Output is correct
18 Correct 460 ms 4308 KB Output is correct
19 Correct 236 ms 4308 KB Output is correct
20 Correct 61 ms 4308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 0 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 0 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 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 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 0 ms 468 KB Output is correct
36 Correct 0 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 0 ms 468 KB Output is correct
40 Correct 0 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 0 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 0 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 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 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 0 ms 468 KB Output is correct
36 Correct 0 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 0 ms 468 KB Output is correct
40 Correct 0 ms 468 KB Output is correct
41 Correct 1 ms 1108 KB Output is correct
42 Correct 1 ms 1108 KB Output is correct
43 Correct 1 ms 1108 KB Output is correct
44 Correct 1 ms 1108 KB Output is correct
45 Correct 2 ms 1108 KB Output is correct
46 Correct 2 ms 1108 KB Output is correct
47 Correct 2 ms 1108 KB Output is correct
48 Correct 3 ms 1108 KB Output is correct
49 Correct 3 ms 1108 KB Output is correct
50 Correct 3 ms 1108 KB Output is correct
51 Correct 6 ms 1108 KB Output is correct
52 Correct 5 ms 1108 KB Output is correct
53 Correct 2 ms 1108 KB Output is correct
54 Correct 3 ms 1108 KB Output is correct
55 Correct 3 ms 1108 KB Output is correct
56 Correct 3 ms 1108 KB Output is correct
57 Correct 3 ms 1108 KB Output is correct
58 Correct 2 ms 1108 KB Output is correct
59 Correct 4 ms 1108 KB Output is correct
60 Correct 3 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 464 ms 4308 KB Output is correct
2 Correct 469 ms 4308 KB Output is correct
3 Correct 456 ms 4308 KB Output is correct
4 Correct 470 ms 4308 KB Output is correct
5 Correct 479 ms 4308 KB Output is correct
6 Correct 518 ms 4308 KB Output is correct
7 Correct 460 ms 4308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 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 2 ms 4308 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4308 KB Output is correct
8 Correct 2 ms 4276 KB Output is correct
9 Correct 2 ms 4308 KB Output is correct
10 Correct 2 ms 4308 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 48 ms 4308 KB Output is correct
13 Correct 43 ms 4308 KB Output is correct
14 Correct 27 ms 4308 KB Output is correct
15 Correct 233 ms 4436 KB Output is correct
16 Correct 244 ms 4300 KB Output is correct
17 Correct 47 ms 4316 KB Output is correct
18 Correct 460 ms 4308 KB Output is correct
19 Correct 236 ms 4308 KB Output is correct
20 Correct 61 ms 4308 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 468 KB Output is correct
37 Correct 0 ms 468 KB Output is correct
38 Correct 0 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 0 ms 468 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 1 ms 468 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 468 KB Output is correct
51 Correct 1 ms 468 KB Output is correct
52 Correct 1 ms 468 KB Output is correct
53 Correct 1 ms 468 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 0 ms 468 KB Output is correct
56 Correct 0 ms 468 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 0 ms 468 KB Output is correct
60 Correct 0 ms 468 KB Output is correct
61 Correct 1 ms 1108 KB Output is correct
62 Correct 1 ms 1108 KB Output is correct
63 Correct 1 ms 1108 KB Output is correct
64 Correct 1 ms 1108 KB Output is correct
65 Correct 2 ms 1108 KB Output is correct
66 Correct 2 ms 1108 KB Output is correct
67 Correct 2 ms 1108 KB Output is correct
68 Correct 3 ms 1108 KB Output is correct
69 Correct 3 ms 1108 KB Output is correct
70 Correct 3 ms 1108 KB Output is correct
71 Correct 6 ms 1108 KB Output is correct
72 Correct 5 ms 1108 KB Output is correct
73 Correct 2 ms 1108 KB Output is correct
74 Correct 3 ms 1108 KB Output is correct
75 Correct 3 ms 1108 KB Output is correct
76 Correct 3 ms 1108 KB Output is correct
77 Correct 3 ms 1108 KB Output is correct
78 Correct 2 ms 1108 KB Output is correct
79 Correct 4 ms 1108 KB Output is correct
80 Correct 3 ms 1116 KB Output is correct
81 Correct 464 ms 4308 KB Output is correct
82 Correct 469 ms 4308 KB Output is correct
83 Correct 456 ms 4308 KB Output is correct
84 Correct 470 ms 4308 KB Output is correct
85 Correct 479 ms 4308 KB Output is correct
86 Correct 518 ms 4308 KB Output is correct
87 Correct 460 ms 4308 KB Output is correct
88 Correct 7 ms 4308 KB Output is correct
89 Correct 8 ms 4308 KB Output is correct
90 Correct 33 ms 4308 KB Output is correct
91 Correct 33 ms 4308 KB Output is correct
92 Correct 125 ms 4308 KB Output is correct
93 Correct 120 ms 4308 KB Output is correct
94 Correct 268 ms 4308 KB Output is correct
95 Correct 335 ms 4312 KB Output is correct
96 Correct 368 ms 4308 KB Output is correct
97 Correct 393 ms 4308 KB Output is correct
98 Correct 234 ms 4308 KB Output is correct
99 Correct 246 ms 4308 KB Output is correct
100 Correct 254 ms 4308 KB Output is correct
101 Correct 227 ms 4308 KB Output is correct
102 Correct 230 ms 4308 KB Output is correct
103 Correct 234 ms 4316 KB Output is correct
104 Correct 267 ms 4308 KB Output is correct
105 Correct 233 ms 4308 KB Output is correct