답안 #800547

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
800547 2023-08-01T16:03:37 Z caganyanmaz Let's Win the Election (JOI22_ho_t3) C++17
33 / 100
490 ms 814956 KB
#include <bits/stdc++.h>
//#define double  long double
#define mp(x...) array<int, 2>({x})
using namespace std;

constexpr static int INF = 1e8;
constexpr static int MXSIZE = 1000;
bitset<MXSIZE> added;
array<int, 2> a[MXSIZE];
array<int, 3> b[MXSIZE];
int n, k;

double calculate(int cc)
{
        int count = 0;
        double cost = 0;
        for (int i = 0; i < cc; i++)
        {
                cost += static_cast<double>(b[i][0]) / (i+1);
                count++;
        }
        for (int i = 0; i < n && count < k; i++)
        {
                if (added[a[i][1]])
                        continue;
                cost += static_cast<double>(a[i][0]) / (cc+1);
                count++;
        }
        assert(count == k);
        return cost;
}


constexpr static int MXSIZE2 = 101;
double dp[MXSIZE2][MXSIZE2][MXSIZE2][MXSIZE2]; // Position, expected value, filled count, current value
array<int, 2> v[MXSIZE2];
void subtask2()
{
        cin >> k;
        for (int i = 0; i < n; i++)
        {
                int aa, bb;
                cin >> aa >> bb;
                bb = (bb == -1) ? INF : bb;
                v[i] = mp(bb, aa);
        }
        for (int i = 0; i < MXSIZE2; i++)
                for (int j = 0; j < MXSIZE2; j++)
                        for (int l = 0; l < MXSIZE2; l++)
                                for (int w = 0; w < MXSIZE2; w++)
                                        if (w != 0 || l != 0)
                                                dp[i][j][l][w] = INF;
        sort(v, v + n);
        for (int i = n-1; i >= 0; i--)
        {
                double bb = v[i][0], aa = v[i][1];
                for (int j = 0; j <= k; j++)
                {
                        for (int l = 0; l <= k; l++)
                        {
                                for (int w = 0; w <= j; w++)
                                {
                                        dp[i][j][l][w] = dp[i+1][j][l][w];
                                        if (l != 0)
                                                dp[i][j][l][w] = min({dp[i][j][l][w], (w > 0) ? (dp[i+1][j][l-1][w-1] + (bb / (j-w+1))) : INF, dp[i+1][j][l-1][w] + (aa / (j+1))} );
                                }
                        }
                }
        }
        double best = INF;
        for (int i = 0; i <= n; i++)
                best = min(best, dp[0][i][k][i]);

        cout << fixed;
        cout << setprecision(20);
        cout << best << "\n";


}

int main()
{
        cin >> n;
        if (n < 100)
        {
                subtask2();
                return 0;
        }
        cin >> k;
        for (int i = 0; i < n; i++)
        {
                int aa, bb;
                cin >> aa >> bb;
                a[i] = mp(aa, i);
                bb = bb == -1 ? INF : bb;
                b[i] = array<int, 3>({bb, -aa, i});
        }
        sort(a, a + n);
        sort(b, b + n);
        double best = INF;
        for (int i = 0; i <= k && (i == 0 || b[i-1][0] != INF); i++)
        {
                if (i > 0)
                        added[b[i-1][2]] = true;
                best = min(best, calculate(i));
        }
        cout << fixed;
        cout << setprecision(20);
        cout << best << "\n";

}
# 결과 실행 시간 메모리 Grader output
1 Correct 320 ms 814844 KB Output is correct
2 Correct 314 ms 814820 KB Output is correct
3 Correct 315 ms 814788 KB Output is correct
4 Correct 320 ms 814916 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 320 ms 814844 KB Output is correct
2 Correct 314 ms 814820 KB Output is correct
3 Correct 315 ms 814788 KB Output is correct
4 Correct 320 ms 814916 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 317 ms 814804 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 288 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 311 ms 814768 KB Output is correct
2 Correct 335 ms 814740 KB Output is correct
3 Correct 311 ms 814796 KB Output is correct
4 Correct 328 ms 814764 KB Output is correct
5 Correct 311 ms 814800 KB Output is correct
6 Correct 314 ms 814736 KB Output is correct
7 Correct 310 ms 814836 KB Output is correct
8 Correct 315 ms 814812 KB Output is correct
9 Correct 311 ms 814816 KB Output is correct
10 Correct 327 ms 814760 KB Output is correct
11 Correct 310 ms 814836 KB Output is correct
12 Correct 314 ms 814840 KB Output is correct
13 Correct 312 ms 814732 KB Output is correct
14 Correct 335 ms 814764 KB Output is correct
15 Correct 315 ms 814724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 311 ms 814768 KB Output is correct
2 Correct 335 ms 814740 KB Output is correct
3 Correct 311 ms 814796 KB Output is correct
4 Correct 328 ms 814764 KB Output is correct
5 Correct 311 ms 814800 KB Output is correct
6 Correct 314 ms 814736 KB Output is correct
7 Correct 310 ms 814836 KB Output is correct
8 Correct 315 ms 814812 KB Output is correct
9 Correct 311 ms 814816 KB Output is correct
10 Correct 327 ms 814760 KB Output is correct
11 Correct 310 ms 814836 KB Output is correct
12 Correct 314 ms 814840 KB Output is correct
13 Correct 312 ms 814732 KB Output is correct
14 Correct 335 ms 814764 KB Output is correct
15 Correct 315 ms 814724 KB Output is correct
16 Correct 318 ms 814816 KB Output is correct
17 Correct 312 ms 814760 KB Output is correct
18 Correct 318 ms 814736 KB Output is correct
19 Correct 314 ms 814804 KB Output is correct
20 Correct 321 ms 814796 KB Output is correct
21 Correct 322 ms 814956 KB Output is correct
22 Correct 318 ms 814796 KB Output is correct
23 Correct 321 ms 814800 KB Output is correct
24 Correct 313 ms 814768 KB Output is correct
25 Correct 490 ms 814936 KB Output is correct
26 Correct 314 ms 814740 KB Output is correct
27 Correct 318 ms 814796 KB Output is correct
28 Correct 314 ms 814724 KB Output is correct
29 Correct 318 ms 814796 KB Output is correct
30 Correct 321 ms 814796 KB Output is correct
31 Correct 315 ms 814804 KB Output is correct
32 Correct 325 ms 814752 KB Output is correct
33 Correct 314 ms 814780 KB Output is correct
34 Correct 322 ms 814744 KB Output is correct
35 Correct 321 ms 814744 KB Output is correct
36 Correct 322 ms 814732 KB Output is correct
37 Correct 325 ms 814820 KB Output is correct
38 Correct 346 ms 814820 KB Output is correct
39 Correct 311 ms 814756 KB Output is correct
40 Correct 320 ms 814840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 311 ms 814768 KB Output is correct
2 Correct 335 ms 814740 KB Output is correct
3 Correct 311 ms 814796 KB Output is correct
4 Correct 328 ms 814764 KB Output is correct
5 Correct 311 ms 814800 KB Output is correct
6 Correct 314 ms 814736 KB Output is correct
7 Correct 310 ms 814836 KB Output is correct
8 Correct 315 ms 814812 KB Output is correct
9 Correct 311 ms 814816 KB Output is correct
10 Correct 327 ms 814760 KB Output is correct
11 Correct 310 ms 814836 KB Output is correct
12 Correct 314 ms 814840 KB Output is correct
13 Correct 312 ms 814732 KB Output is correct
14 Correct 335 ms 814764 KB Output is correct
15 Correct 315 ms 814724 KB Output is correct
16 Correct 318 ms 814816 KB Output is correct
17 Correct 312 ms 814760 KB Output is correct
18 Correct 318 ms 814736 KB Output is correct
19 Correct 314 ms 814804 KB Output is correct
20 Correct 321 ms 814796 KB Output is correct
21 Correct 322 ms 814956 KB Output is correct
22 Correct 318 ms 814796 KB Output is correct
23 Correct 321 ms 814800 KB Output is correct
24 Correct 313 ms 814768 KB Output is correct
25 Correct 490 ms 814936 KB Output is correct
26 Correct 314 ms 814740 KB Output is correct
27 Correct 318 ms 814796 KB Output is correct
28 Correct 314 ms 814724 KB Output is correct
29 Correct 318 ms 814796 KB Output is correct
30 Correct 321 ms 814796 KB Output is correct
31 Correct 315 ms 814804 KB Output is correct
32 Correct 325 ms 814752 KB Output is correct
33 Correct 314 ms 814780 KB Output is correct
34 Correct 322 ms 814744 KB Output is correct
35 Correct 321 ms 814744 KB Output is correct
36 Correct 322 ms 814732 KB Output is correct
37 Correct 325 ms 814820 KB Output is correct
38 Correct 346 ms 814820 KB Output is correct
39 Correct 311 ms 814756 KB Output is correct
40 Correct 320 ms 814840 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Incorrect 0 ms 212 KB Output isn't correct
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 320 ms 814844 KB Output is correct
2 Correct 314 ms 814820 KB Output is correct
3 Correct 315 ms 814788 KB Output is correct
4 Correct 320 ms 814916 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 317 ms 814804 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 288 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 311 ms 814768 KB Output is correct
22 Correct 335 ms 814740 KB Output is correct
23 Correct 311 ms 814796 KB Output is correct
24 Correct 328 ms 814764 KB Output is correct
25 Correct 311 ms 814800 KB Output is correct
26 Correct 314 ms 814736 KB Output is correct
27 Correct 310 ms 814836 KB Output is correct
28 Correct 315 ms 814812 KB Output is correct
29 Correct 311 ms 814816 KB Output is correct
30 Correct 327 ms 814760 KB Output is correct
31 Correct 310 ms 814836 KB Output is correct
32 Correct 314 ms 814840 KB Output is correct
33 Correct 312 ms 814732 KB Output is correct
34 Correct 335 ms 814764 KB Output is correct
35 Correct 315 ms 814724 KB Output is correct
36 Correct 318 ms 814816 KB Output is correct
37 Correct 312 ms 814760 KB Output is correct
38 Correct 318 ms 814736 KB Output is correct
39 Correct 314 ms 814804 KB Output is correct
40 Correct 321 ms 814796 KB Output is correct
41 Correct 322 ms 814956 KB Output is correct
42 Correct 318 ms 814796 KB Output is correct
43 Correct 321 ms 814800 KB Output is correct
44 Correct 313 ms 814768 KB Output is correct
45 Correct 490 ms 814936 KB Output is correct
46 Correct 314 ms 814740 KB Output is correct
47 Correct 318 ms 814796 KB Output is correct
48 Correct 314 ms 814724 KB Output is correct
49 Correct 318 ms 814796 KB Output is correct
50 Correct 321 ms 814796 KB Output is correct
51 Correct 315 ms 814804 KB Output is correct
52 Correct 325 ms 814752 KB Output is correct
53 Correct 314 ms 814780 KB Output is correct
54 Correct 322 ms 814744 KB Output is correct
55 Correct 321 ms 814744 KB Output is correct
56 Correct 322 ms 814732 KB Output is correct
57 Correct 325 ms 814820 KB Output is correct
58 Correct 346 ms 814820 KB Output is correct
59 Correct 311 ms 814756 KB Output is correct
60 Correct 320 ms 814840 KB Output is correct
61 Correct 0 ms 212 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Incorrect 0 ms 212 KB Output isn't correct
64 Halted 0 ms 0 KB -