Submission #643568

# Submission time Handle Problem Language Result Execution time Memory
643568 2022-09-22T13:15:57 Z browntoad Let's Win the Election (JOI22_ho_t3) C++14
100 / 100
1623 ms 8400 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast", "unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define pdd pair<double ,double>
#define pcc pair<char, char> 
#define endl '\n'
//#define TOAD
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#define IOS()
#else
#define bug(...)
#define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif
 
const ll inf = 1ll<<60;
const int iinf=2147483647;
const ll mod = 1e9+7;
const ll maxn=505;
const double PI=acos(-1);
 
ll pw(ll x, ll p, ll m=mod){
    ll ret=1;
    while (p>0){
        if (p&1){
            ret*=x;
            ret%=m;
        }
        x*=x;
        x%=m;
        p>>=1;
    }
    return ret;
}
 
ll inv(ll a, ll m=mod){
    return pw(a,m-2);
}
 
//=======================================================================================
 
int n, k;
vector<pii> vc;
long double dp[maxn][maxn], sf[maxn][maxn];
bool cmp(pii a, pii b){
    if (a.s==-1&&b.s==-1){
        return a.f<b.f;
    }
    if (a.s==-1||b.s==-1){
        return a.s>b.s;
    }
    return a.s<b.s;
}
 
signed main (){
    IOS();
    cout<<fixed<<setprecision(15);
    cin>>n>>k;
    REP(i, n){
        int x, y; cin>>x>>y;
        vc.pb({x, y});
    }
    sort(ALL(vc), cmp);
    REP(i, maxn){
        REP(j, maxn){
            if (j==0) sf[i][j]=0;
            else sf[i][j]=iinf;
        }
    }
    RREP(i, n){
        vector<int> cur;
        FOR(j, i, n){
            cur.pb(vc[j].f);
        }
        sort(ALL(cur));
        REP1(j, k){
            if (j>SZ(cur)) break;
            else sf[i][j]=sf[i][j-1]+cur[j-1];
        }
    }
    long double res=sf[0][k];
    REP1(t, k){
        REP(i, n){
            REP(j, t+1){
                dp[i][j]=iinf;
            }
        }
        REP(i, n){
            if (i==0){
                dp[i][0]=(0.0+vc[i].f)/(t+1);
                if (vc[i].s!=-1) dp[i][1]=(0.0+vc[i].s);
                continue;
            }
            REP(j, t+1){
                if (j==0){
                    dp[i][0]=dp[i-1][0]+(0.0+vc[i].f)/(t+1);
                }
                else dp[i][j]=min(dp[i-1][j]+(0.0+vc[i].f)/(t+1), ((vc[i].s!=-1)?(dp[i-1][j-1]+(0.0+vc[i].s)/(j)):(0.0+iinf)));
            }
        }
        REP(i, n){
          	if (k<(i+1)) continue;
            res=min(res, dp[i][t]+sf[i+1][k-(i+1)]/(t+1));
        }
    }
    cout<<res<<endl;
 
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4308 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 3 ms 4308 KB Output is correct
5 Correct 19 ms 6612 KB Output is correct
6 Correct 96 ms 7160 KB Output is correct
7 Correct 356 ms 8260 KB Output is correct
8 Correct 784 ms 8240 KB Output is correct
9 Correct 1380 ms 8272 KB Output is correct
10 Correct 683 ms 8396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4308 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 3 ms 4308 KB Output is correct
5 Correct 19 ms 6612 KB Output is correct
6 Correct 96 ms 7160 KB Output is correct
7 Correct 356 ms 8260 KB Output is correct
8 Correct 784 ms 8240 KB Output is correct
9 Correct 1380 ms 8272 KB Output is correct
10 Correct 683 ms 8396 KB Output is correct
11 Correct 2 ms 4308 KB Output is correct
12 Correct 151 ms 7456 KB Output is correct
13 Correct 148 ms 7604 KB Output is correct
14 Correct 136 ms 7400 KB Output is correct
15 Correct 793 ms 8368 KB Output is correct
16 Correct 749 ms 8272 KB Output is correct
17 Correct 696 ms 8172 KB Output is correct
18 Correct 1622 ms 8340 KB Output is correct
19 Correct 1512 ms 8348 KB Output is correct
20 Correct 1421 ms 8400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4308 KB Output is correct
2 Correct 3 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 2 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 3 ms 4308 KB Output is correct
7 Correct 2 ms 4308 KB Output is correct
8 Correct 2 ms 4308 KB Output is correct
9 Correct 2 ms 4308 KB Output is correct
10 Correct 2 ms 4284 KB Output is correct
11 Correct 2 ms 4308 KB Output is correct
12 Correct 2 ms 4260 KB Output is correct
13 Correct 2 ms 4308 KB Output is correct
14 Correct 2 ms 4308 KB Output is correct
15 Correct 2 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4308 KB Output is correct
2 Correct 3 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 2 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 3 ms 4308 KB Output is correct
7 Correct 2 ms 4308 KB Output is correct
8 Correct 2 ms 4308 KB Output is correct
9 Correct 2 ms 4308 KB Output is correct
10 Correct 2 ms 4284 KB Output is correct
11 Correct 2 ms 4308 KB Output is correct
12 Correct 2 ms 4260 KB Output is correct
13 Correct 2 ms 4308 KB Output is correct
14 Correct 2 ms 4308 KB Output is correct
15 Correct 2 ms 4308 KB Output is correct
16 Correct 2 ms 4308 KB Output is correct
17 Correct 3 ms 4308 KB Output is correct
18 Correct 2 ms 4308 KB Output is correct
19 Correct 3 ms 4408 KB Output is correct
20 Correct 3 ms 4308 KB Output is correct
21 Correct 3 ms 4308 KB Output is correct
22 Correct 2 ms 4308 KB Output is correct
23 Correct 3 ms 4308 KB Output is correct
24 Correct 2 ms 4308 KB Output is correct
25 Correct 3 ms 4308 KB Output is correct
26 Correct 2 ms 4308 KB Output is correct
27 Correct 2 ms 4308 KB Output is correct
28 Correct 2 ms 4308 KB Output is correct
29 Correct 2 ms 4308 KB Output is correct
30 Correct 2 ms 4308 KB Output is correct
31 Correct 2 ms 4308 KB Output is correct
32 Correct 2 ms 4308 KB Output is correct
33 Correct 2 ms 4308 KB Output is correct
34 Correct 3 ms 4308 KB Output is correct
35 Correct 3 ms 4308 KB Output is correct
36 Correct 3 ms 4308 KB Output is correct
37 Correct 3 ms 4308 KB Output is correct
38 Correct 3 ms 4308 KB Output is correct
39 Correct 3 ms 4308 KB Output is correct
40 Correct 3 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4308 KB Output is correct
2 Correct 3 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 2 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 3 ms 4308 KB Output is correct
7 Correct 2 ms 4308 KB Output is correct
8 Correct 2 ms 4308 KB Output is correct
9 Correct 2 ms 4308 KB Output is correct
10 Correct 2 ms 4284 KB Output is correct
11 Correct 2 ms 4308 KB Output is correct
12 Correct 2 ms 4260 KB Output is correct
13 Correct 2 ms 4308 KB Output is correct
14 Correct 2 ms 4308 KB Output is correct
15 Correct 2 ms 4308 KB Output is correct
16 Correct 2 ms 4308 KB Output is correct
17 Correct 3 ms 4308 KB Output is correct
18 Correct 2 ms 4308 KB Output is correct
19 Correct 3 ms 4408 KB Output is correct
20 Correct 3 ms 4308 KB Output is correct
21 Correct 3 ms 4308 KB Output is correct
22 Correct 2 ms 4308 KB Output is correct
23 Correct 3 ms 4308 KB Output is correct
24 Correct 2 ms 4308 KB Output is correct
25 Correct 3 ms 4308 KB Output is correct
26 Correct 2 ms 4308 KB Output is correct
27 Correct 2 ms 4308 KB Output is correct
28 Correct 2 ms 4308 KB Output is correct
29 Correct 2 ms 4308 KB Output is correct
30 Correct 2 ms 4308 KB Output is correct
31 Correct 2 ms 4308 KB Output is correct
32 Correct 2 ms 4308 KB Output is correct
33 Correct 2 ms 4308 KB Output is correct
34 Correct 3 ms 4308 KB Output is correct
35 Correct 3 ms 4308 KB Output is correct
36 Correct 3 ms 4308 KB Output is correct
37 Correct 3 ms 4308 KB Output is correct
38 Correct 3 ms 4308 KB Output is correct
39 Correct 3 ms 4308 KB Output is correct
40 Correct 3 ms 4308 KB Output is correct
41 Correct 3 ms 4692 KB Output is correct
42 Correct 3 ms 4692 KB Output is correct
43 Correct 4 ms 4692 KB Output is correct
44 Correct 4 ms 4692 KB Output is correct
45 Correct 6 ms 4776 KB Output is correct
46 Correct 6 ms 4776 KB Output is correct
47 Correct 9 ms 4800 KB Output is correct
48 Correct 9 ms 4808 KB Output is correct
49 Correct 11 ms 4812 KB Output is correct
50 Correct 12 ms 4820 KB Output is correct
51 Correct 17 ms 4828 KB Output is correct
52 Correct 16 ms 4820 KB Output is correct
53 Correct 8 ms 4704 KB Output is correct
54 Correct 8 ms 4820 KB Output is correct
55 Correct 9 ms 4820 KB Output is correct
56 Correct 9 ms 4792 KB Output is correct
57 Correct 9 ms 4820 KB Output is correct
58 Correct 8 ms 4744 KB Output is correct
59 Correct 9 ms 4820 KB Output is correct
60 Correct 8 ms 4820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1615 ms 8232 KB Output is correct
2 Correct 1623 ms 8244 KB Output is correct
3 Correct 1611 ms 8348 KB Output is correct
4 Correct 1591 ms 8272 KB Output is correct
5 Correct 1606 ms 8304 KB Output is correct
6 Correct 1621 ms 8328 KB Output is correct
7 Correct 1603 ms 8364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4308 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 3 ms 4308 KB Output is correct
5 Correct 19 ms 6612 KB Output is correct
6 Correct 96 ms 7160 KB Output is correct
7 Correct 356 ms 8260 KB Output is correct
8 Correct 784 ms 8240 KB Output is correct
9 Correct 1380 ms 8272 KB Output is correct
10 Correct 683 ms 8396 KB Output is correct
11 Correct 2 ms 4308 KB Output is correct
12 Correct 151 ms 7456 KB Output is correct
13 Correct 148 ms 7604 KB Output is correct
14 Correct 136 ms 7400 KB Output is correct
15 Correct 793 ms 8368 KB Output is correct
16 Correct 749 ms 8272 KB Output is correct
17 Correct 696 ms 8172 KB Output is correct
18 Correct 1622 ms 8340 KB Output is correct
19 Correct 1512 ms 8348 KB Output is correct
20 Correct 1421 ms 8400 KB Output is correct
21 Correct 3 ms 4308 KB Output is correct
22 Correct 3 ms 4308 KB Output is correct
23 Correct 2 ms 4308 KB Output is correct
24 Correct 2 ms 4308 KB Output is correct
25 Correct 2 ms 4308 KB Output is correct
26 Correct 3 ms 4308 KB Output is correct
27 Correct 2 ms 4308 KB Output is correct
28 Correct 2 ms 4308 KB Output is correct
29 Correct 2 ms 4308 KB Output is correct
30 Correct 2 ms 4284 KB Output is correct
31 Correct 2 ms 4308 KB Output is correct
32 Correct 2 ms 4260 KB Output is correct
33 Correct 2 ms 4308 KB Output is correct
34 Correct 2 ms 4308 KB Output is correct
35 Correct 2 ms 4308 KB Output is correct
36 Correct 2 ms 4308 KB Output is correct
37 Correct 3 ms 4308 KB Output is correct
38 Correct 2 ms 4308 KB Output is correct
39 Correct 3 ms 4408 KB Output is correct
40 Correct 3 ms 4308 KB Output is correct
41 Correct 3 ms 4308 KB Output is correct
42 Correct 2 ms 4308 KB Output is correct
43 Correct 3 ms 4308 KB Output is correct
44 Correct 2 ms 4308 KB Output is correct
45 Correct 3 ms 4308 KB Output is correct
46 Correct 2 ms 4308 KB Output is correct
47 Correct 2 ms 4308 KB Output is correct
48 Correct 2 ms 4308 KB Output is correct
49 Correct 2 ms 4308 KB Output is correct
50 Correct 2 ms 4308 KB Output is correct
51 Correct 2 ms 4308 KB Output is correct
52 Correct 2 ms 4308 KB Output is correct
53 Correct 2 ms 4308 KB Output is correct
54 Correct 3 ms 4308 KB Output is correct
55 Correct 3 ms 4308 KB Output is correct
56 Correct 3 ms 4308 KB Output is correct
57 Correct 3 ms 4308 KB Output is correct
58 Correct 3 ms 4308 KB Output is correct
59 Correct 3 ms 4308 KB Output is correct
60 Correct 3 ms 4308 KB Output is correct
61 Correct 3 ms 4692 KB Output is correct
62 Correct 3 ms 4692 KB Output is correct
63 Correct 4 ms 4692 KB Output is correct
64 Correct 4 ms 4692 KB Output is correct
65 Correct 6 ms 4776 KB Output is correct
66 Correct 6 ms 4776 KB Output is correct
67 Correct 9 ms 4800 KB Output is correct
68 Correct 9 ms 4808 KB Output is correct
69 Correct 11 ms 4812 KB Output is correct
70 Correct 12 ms 4820 KB Output is correct
71 Correct 17 ms 4828 KB Output is correct
72 Correct 16 ms 4820 KB Output is correct
73 Correct 8 ms 4704 KB Output is correct
74 Correct 8 ms 4820 KB Output is correct
75 Correct 9 ms 4820 KB Output is correct
76 Correct 9 ms 4792 KB Output is correct
77 Correct 9 ms 4820 KB Output is correct
78 Correct 8 ms 4744 KB Output is correct
79 Correct 9 ms 4820 KB Output is correct
80 Correct 8 ms 4820 KB Output is correct
81 Correct 1615 ms 8232 KB Output is correct
82 Correct 1623 ms 8244 KB Output is correct
83 Correct 1611 ms 8348 KB Output is correct
84 Correct 1591 ms 8272 KB Output is correct
85 Correct 1606 ms 8304 KB Output is correct
86 Correct 1621 ms 8328 KB Output is correct
87 Correct 1603 ms 8364 KB Output is correct
88 Correct 29 ms 6612 KB Output is correct
89 Correct 25 ms 6676 KB Output is correct
90 Correct 112 ms 7168 KB Output is correct
91 Correct 114 ms 7248 KB Output is correct
92 Correct 417 ms 8296 KB Output is correct
93 Correct 408 ms 8280 KB Output is correct
94 Correct 923 ms 8188 KB Output is correct
95 Correct 915 ms 8180 KB Output is correct
96 Correct 1312 ms 8216 KB Output is correct
97 Correct 1345 ms 8392 KB Output is correct
98 Correct 810 ms 8172 KB Output is correct
99 Correct 800 ms 8304 KB Output is correct
100 Correct 803 ms 8344 KB Output is correct
101 Correct 804 ms 8268 KB Output is correct
102 Correct 807 ms 8268 KB Output is correct
103 Correct 805 ms 8360 KB Output is correct
104 Correct 800 ms 8276 KB Output is correct
105 Correct 793 ms 8272 KB Output is correct