Submission #696574

# Submission time Handle Problem Language Result Execution time Memory
696574 2023-02-06T22:36:30 Z Deepesson Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
1648 ms 4404 KB
#include <bits/stdc++.h>

#define MAX 505
typedef std::pair<double,int> pdd;
typedef std::pair<long long ,long long> pii;
using ll = long long;
pdd tab[MAX][MAX];
int K=0;
std::vector<pii> regs;
int N;
long long C;
double inf = 1LL<<50LL;
pdd dp(void){
    for(int i=0;i!=MAX;++i){
        tab[N][i]={inf,0};
    }
    tab[N][0]={0.0,0};
    for(int i=N-1;i!=-1;--i){
        for(int j=0;j<=K;++j){
            tab[i][j]={inf,0};
            const double pegou = K-j+1;
            if(j){
                double custo = (double)regs[i].first/pegou;
                pdd g = tab[i+1][j-1];
                g.first+=custo;
                tab[i][j]=std::min(tab[i][j],g);
            }
            if(regs[i].second<=C){
                double custo = (double)regs[i].second/(double)(K+1);
                pdd g = tab[i+1][j];
                g.first+=custo-((double)C/(double)(K+1));
                g.second--;
                tab[i][j]=std::min(tab[i][j],g);
            }else tab[i][j]=std::min(tab[i+1][j],tab[i][j]);
        }
    }
    return tab[0][K];
}
pdd simula(ll kok){
    C=kok;
    return dp();
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    int obj;
    std::cin>>N>>obj;
    for(int i=0;i!=N;++i){
        ll a,b;
        std::cin>>a>>b;
        if(b==-1)b=inf;
        regs.push_back({b,a});
    }
    std::sort(regs.begin(),regs.end());
    double ans=inf;
    ll last=1000;
    for(K=0;K<=obj;++K){
        while(K!=obj&&last!=1){
            auto vec = simula(last-1);
            if(abs(vec.second)>=obj-K&&last){
                --last;
            }else break;
        }
        auto kek = simula(last);
        kek.second*=-1;
        kek.first+=(double)kek.second*((double)last/(double)(K+1));
        ///Pegar quantos a mais selecionei
        ll dif = kek.second-(obj-K);
        ///Descontar os extras (note que eu consigo garantir que o custo eh L)
        kek.first-=((double)(dif*last))/(double)(K+1);
        ans=std::min(ans,kek.first);
    }
    std::cout<<std::fixed<<std::setprecision(20)<<ans<<"\n";
}
# 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 340 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 17 ms 2668 KB Output is correct
6 Correct 78 ms 3240 KB Output is correct
7 Correct 309 ms 4288 KB Output is correct
8 Correct 614 ms 4280 KB Output is correct
9 Correct 1091 ms 4284 KB Output is correct
10 Correct 301 ms 4292 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 340 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 17 ms 2668 KB Output is correct
6 Correct 78 ms 3240 KB Output is correct
7 Correct 309 ms 4288 KB Output is correct
8 Correct 614 ms 4280 KB Output is correct
9 Correct 1091 ms 4284 KB Output is correct
10 Correct 301 ms 4292 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 56 ms 3444 KB Output is correct
13 Correct 119 ms 3504 KB Output is correct
14 Correct 110 ms 3436 KB Output is correct
15 Correct 313 ms 4164 KB Output is correct
16 Correct 661 ms 4300 KB Output is correct
17 Correct 582 ms 4276 KB Output is correct
18 Correct 714 ms 4388 KB Output is correct
19 Correct 1625 ms 4284 KB Output is correct
20 Correct 1194 ms 4404 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 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 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 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 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 340 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 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 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 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 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 340 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 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 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 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 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 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 340 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 2 ms 724 KB Output is correct
42 Correct 2 ms 724 KB Output is correct
43 Correct 4 ms 724 KB Output is correct
44 Correct 2 ms 724 KB Output is correct
45 Correct 5 ms 724 KB Output is correct
46 Correct 8 ms 724 KB Output is correct
47 Correct 11 ms 844 KB Output is correct
48 Correct 12 ms 840 KB Output is correct
49 Correct 16 ms 852 KB Output is correct
50 Correct 23 ms 860 KB Output is correct
51 Correct 42 ms 856 KB Output is correct
52 Correct 28 ms 896 KB Output is correct
53 Correct 6 ms 852 KB Output is correct
54 Correct 5 ms 852 KB Output is correct
55 Correct 5 ms 848 KB Output is correct
56 Correct 8 ms 840 KB Output is correct
57 Correct 5 ms 780 KB Output is correct
58 Correct 7 ms 844 KB Output is correct
59 Correct 6 ms 852 KB Output is correct
60 Correct 8 ms 848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1514 ms 4284 KB Output is correct
2 Correct 1648 ms 4288 KB Output is correct
3 Correct 1192 ms 4284 KB Output is correct
4 Correct 983 ms 4376 KB Output is correct
5 Correct 826 ms 4284 KB Output is correct
6 Correct 675 ms 4300 KB Output is correct
7 Correct 881 ms 4332 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 340 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 17 ms 2668 KB Output is correct
6 Correct 78 ms 3240 KB Output is correct
7 Correct 309 ms 4288 KB Output is correct
8 Correct 614 ms 4280 KB Output is correct
9 Correct 1091 ms 4284 KB Output is correct
10 Correct 301 ms 4292 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 56 ms 3444 KB Output is correct
13 Correct 119 ms 3504 KB Output is correct
14 Correct 110 ms 3436 KB Output is correct
15 Correct 313 ms 4164 KB Output is correct
16 Correct 661 ms 4300 KB Output is correct
17 Correct 582 ms 4276 KB Output is correct
18 Correct 714 ms 4388 KB Output is correct
19 Correct 1625 ms 4284 KB Output is correct
20 Correct 1194 ms 4404 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 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 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 324 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 328 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 328 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 3 ms 340 KB Output is correct
46 Correct 2 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 2 ms 724 KB Output is correct
62 Correct 2 ms 724 KB Output is correct
63 Correct 4 ms 724 KB Output is correct
64 Correct 2 ms 724 KB Output is correct
65 Correct 5 ms 724 KB Output is correct
66 Correct 8 ms 724 KB Output is correct
67 Correct 11 ms 844 KB Output is correct
68 Correct 12 ms 840 KB Output is correct
69 Correct 16 ms 852 KB Output is correct
70 Correct 23 ms 860 KB Output is correct
71 Correct 42 ms 856 KB Output is correct
72 Correct 28 ms 896 KB Output is correct
73 Correct 6 ms 852 KB Output is correct
74 Correct 5 ms 852 KB Output is correct
75 Correct 5 ms 848 KB Output is correct
76 Correct 8 ms 840 KB Output is correct
77 Correct 5 ms 780 KB Output is correct
78 Correct 7 ms 844 KB Output is correct
79 Correct 6 ms 852 KB Output is correct
80 Correct 8 ms 848 KB Output is correct
81 Correct 1514 ms 4284 KB Output is correct
82 Correct 1648 ms 4288 KB Output is correct
83 Correct 1192 ms 4284 KB Output is correct
84 Correct 983 ms 4376 KB Output is correct
85 Correct 826 ms 4284 KB Output is correct
86 Correct 675 ms 4300 KB Output is correct
87 Correct 881 ms 4332 KB Output is correct
88 Correct 15 ms 2644 KB Output is correct
89 Correct 10 ms 2716 KB Output is correct
90 Correct 59 ms 3312 KB Output is correct
91 Correct 44 ms 3240 KB Output is correct
92 Correct 242 ms 4276 KB Output is correct
93 Correct 177 ms 4212 KB Output is correct
94 Correct 632 ms 4316 KB Output is correct
95 Correct 481 ms 4284 KB Output is correct
96 Correct 1095 ms 4356 KB Output is correct
97 Correct 739 ms 4288 KB Output is correct
98 Correct 392 ms 4284 KB Output is correct
99 Correct 321 ms 4280 KB Output is correct
100 Correct 308 ms 4284 KB Output is correct
101 Correct 386 ms 4368 KB Output is correct
102 Correct 374 ms 4240 KB Output is correct
103 Correct 384 ms 4356 KB Output is correct
104 Correct 385 ms 4228 KB Output is correct
105 Correct 191 ms 4284 KB Output is correct