답안 #888247

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
888247 2023-12-16T15:58:45 Z salmon Let's Win the Election (JOI22_ho_t3) C++14
100 / 100
765 ms 8792 KB
#include <bits/stdc++.h>
using namespace std;

#define foreach(a,b,i) for(type(a) i = a; i <= b; i++)
#define type(x) __typeof(x)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

int N,K;
vector<pair<long double,int>> v;
int A[510];
long double B[510];
long double pre[510][510];
const long double inf = 1e20;
long double memo[510][510];

int main(){
    scanf(" %d",&N);
    scanf(" %d",&K);

    for(int i = 1; i <= N; i++){
        scanf(" %d",&A[i]);
        int h;
        scanf(" %d",&h);
        if(h == -1) B[i] = inf;
        else B[i] = h;
        v.pb(mp(B[i],i));
    }

    v.pb(mp(-1,-1));

    sort(v.begin(),v.end());

    foreach(0,N - 1,i){
        pre[i][i] = 0;
        foreach(i + 1, N, j){
            pre[j][i] = pre[j - 1][i] + B[v[j].second] / (long double) (j - i);
        }
    }

    long double big = inf;

    foreach(0,K,i){
        foreach(0,K,k){
            memo[0][k] = inf;
        }

        memo[0][0] = pre[i][0] - pre[0][0];

        //printf("%Lf\n",memo[0][0]);

        foreach(1,N, j){
            foreach(0, K - i, k){
                memo[j][k] = inf;
                if(k == 0){
                    memo[j][k] = memo[j - 1][k];
                }
                else{
                    if(j <= i + k - 1){
                        memo[j][k] = min(memo[j - 1][k], memo[j - 1][k - 1] + A[v[j].second]/(long double)(i+1) + pre[i + k][k] - pre[j][k]  - (pre[i + k - 1][k - 1] - pre[j - 1][k - 1]) );
                    }
                    else{
                        memo[j][k] = min(memo[j - 1][k], memo[j - 1][k - 1] + A[v[j].second]/(long double)(i+1));
                    }
                }
                //printf("%Lf %d %d\n",memo[j][k],j,k);
            }
        }

        //printf("\n%Lf %d\n\n",memo[N][K - i],i);
        big = min(big,memo[N][K - i]);
    }

    printf("%Lf",big);


}
/*
7
7
4 -1
11 -1
6 -1
12 -1
36 -1
11 -1
20 -1
*/

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     scanf(" %d",&N);
      |     ~~~~~^~~~~~~~~~
Main.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf(" %d",&K);
      |     ~~~~~^~~~~~~~~~
Main.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         scanf(" %d",&A[i]);
      |         ~~~~~^~~~~~~~~~~~~
Main.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         scanf(" %d",&h);
      |         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 8 ms 8284 KB Output is correct
6 Correct 38 ms 8284 KB Output is correct
7 Correct 163 ms 8540 KB Output is correct
8 Correct 377 ms 8536 KB Output is correct
9 Correct 724 ms 8536 KB Output is correct
10 Correct 327 ms 8536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 8 ms 8284 KB Output is correct
6 Correct 38 ms 8284 KB Output is correct
7 Correct 163 ms 8540 KB Output is correct
8 Correct 377 ms 8536 KB Output is correct
9 Correct 724 ms 8536 KB Output is correct
10 Correct 327 ms 8536 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 55 ms 8444 KB Output is correct
13 Correct 54 ms 8284 KB Output is correct
14 Correct 54 ms 8284 KB Output is correct
15 Correct 321 ms 8540 KB Output is correct
16 Correct 321 ms 8536 KB Output is correct
17 Correct 326 ms 8540 KB Output is correct
18 Correct 717 ms 8540 KB Output is correct
19 Correct 720 ms 8540 KB Output is correct
20 Correct 745 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2392 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2392 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 2 ms 6492 KB Output is correct
42 Correct 1 ms 6492 KB Output is correct
43 Correct 1 ms 6492 KB Output is correct
44 Correct 2 ms 6492 KB Output is correct
45 Correct 2 ms 6488 KB Output is correct
46 Correct 2 ms 6488 KB Output is correct
47 Correct 3 ms 6492 KB Output is correct
48 Correct 3 ms 6696 KB Output is correct
49 Correct 4 ms 6492 KB Output is correct
50 Correct 5 ms 6492 KB Output is correct
51 Correct 7 ms 6696 KB Output is correct
52 Correct 7 ms 6744 KB Output is correct
53 Correct 3 ms 6492 KB Output is correct
54 Correct 3 ms 6492 KB Output is correct
55 Correct 3 ms 6492 KB Output is correct
56 Correct 3 ms 6492 KB Output is correct
57 Correct 3 ms 6488 KB Output is correct
58 Correct 3 ms 6492 KB Output is correct
59 Correct 3 ms 6488 KB Output is correct
60 Correct 5 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 712 ms 8540 KB Output is correct
2 Correct 716 ms 8792 KB Output is correct
3 Correct 718 ms 8540 KB Output is correct
4 Correct 727 ms 8540 KB Output is correct
5 Correct 765 ms 8540 KB Output is correct
6 Correct 728 ms 8536 KB Output is correct
7 Correct 718 ms 8788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 8 ms 8284 KB Output is correct
6 Correct 38 ms 8284 KB Output is correct
7 Correct 163 ms 8540 KB Output is correct
8 Correct 377 ms 8536 KB Output is correct
9 Correct 724 ms 8536 KB Output is correct
10 Correct 327 ms 8536 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 55 ms 8444 KB Output is correct
13 Correct 54 ms 8284 KB Output is correct
14 Correct 54 ms 8284 KB Output is correct
15 Correct 321 ms 8540 KB Output is correct
16 Correct 321 ms 8536 KB Output is correct
17 Correct 326 ms 8540 KB Output is correct
18 Correct 717 ms 8540 KB Output is correct
19 Correct 720 ms 8540 KB Output is correct
20 Correct 745 ms 8540 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 0 ms 2392 KB Output is correct
30 Correct 0 ms 2396 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2392 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 0 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 0 ms 2396 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 0 ms 2396 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 1 ms 2392 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 1 ms 2396 KB Output is correct
59 Correct 1 ms 2396 KB Output is correct
60 Correct 1 ms 2396 KB Output is correct
61 Correct 2 ms 6492 KB Output is correct
62 Correct 1 ms 6492 KB Output is correct
63 Correct 1 ms 6492 KB Output is correct
64 Correct 2 ms 6492 KB Output is correct
65 Correct 2 ms 6488 KB Output is correct
66 Correct 2 ms 6488 KB Output is correct
67 Correct 3 ms 6492 KB Output is correct
68 Correct 3 ms 6696 KB Output is correct
69 Correct 4 ms 6492 KB Output is correct
70 Correct 5 ms 6492 KB Output is correct
71 Correct 7 ms 6696 KB Output is correct
72 Correct 7 ms 6744 KB Output is correct
73 Correct 3 ms 6492 KB Output is correct
74 Correct 3 ms 6492 KB Output is correct
75 Correct 3 ms 6492 KB Output is correct
76 Correct 3 ms 6492 KB Output is correct
77 Correct 3 ms 6488 KB Output is correct
78 Correct 3 ms 6492 KB Output is correct
79 Correct 3 ms 6488 KB Output is correct
80 Correct 5 ms 6748 KB Output is correct
81 Correct 712 ms 8540 KB Output is correct
82 Correct 716 ms 8792 KB Output is correct
83 Correct 718 ms 8540 KB Output is correct
84 Correct 727 ms 8540 KB Output is correct
85 Correct 765 ms 8540 KB Output is correct
86 Correct 728 ms 8536 KB Output is correct
87 Correct 718 ms 8788 KB Output is correct
88 Correct 8 ms 8536 KB Output is correct
89 Correct 8 ms 8284 KB Output is correct
90 Correct 39 ms 8448 KB Output is correct
91 Correct 44 ms 8284 KB Output is correct
92 Correct 168 ms 8540 KB Output is correct
93 Correct 154 ms 8540 KB Output is correct
94 Correct 374 ms 8536 KB Output is correct
95 Correct 408 ms 8540 KB Output is correct
96 Correct 563 ms 8784 KB Output is correct
97 Correct 568 ms 8540 KB Output is correct
98 Correct 326 ms 8624 KB Output is correct
99 Correct 322 ms 8540 KB Output is correct
100 Correct 333 ms 8548 KB Output is correct
101 Correct 329 ms 8540 KB Output is correct
102 Correct 330 ms 8536 KB Output is correct
103 Correct 326 ms 8536 KB Output is correct
104 Correct 328 ms 8536 KB Output is correct
105 Correct 321 ms 8540 KB Output is correct