답안 #643567

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
643567 2022-09-22T13:11:48 Z browntoad Let's Win the Election (JOI22_ho_t3) C++14
100 / 100
1672 ms 8424 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]=inf;
        }
    }
    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]=inf;
            }
        }
        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+inf)));
            }
        }
        REP(i, n){
            res=min(res, dp[i][t]+sf[i+1][k-(i+1)]/(t+1));
        }
    }
    cout<<res<<endl;
 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 21 ms 6680 KB Output is correct
6 Correct 101 ms 7280 KB Output is correct
7 Correct 377 ms 8156 KB Output is correct
8 Correct 808 ms 8396 KB Output is correct
9 Correct 1416 ms 8272 KB Output is correct
10 Correct 708 ms 8268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 21 ms 6680 KB Output is correct
6 Correct 101 ms 7280 KB Output is correct
7 Correct 377 ms 8156 KB Output is correct
8 Correct 808 ms 8396 KB Output is correct
9 Correct 1416 ms 8272 KB Output is correct
10 Correct 708 ms 8268 KB Output is correct
11 Correct 2 ms 4308 KB Output is correct
12 Correct 167 ms 7436 KB Output is correct
13 Correct 147 ms 7392 KB Output is correct
14 Correct 140 ms 7480 KB Output is correct
15 Correct 816 ms 8264 KB Output is correct
16 Correct 777 ms 8284 KB Output is correct
17 Correct 750 ms 8268 KB Output is correct
18 Correct 1672 ms 8276 KB Output is correct
19 Correct 1552 ms 8276 KB Output is correct
20 Correct 1482 ms 8276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4308 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 3 ms 4308 KB Output is correct
4 Correct 3 ms 4308 KB Output is correct
5 Correct 3 ms 4308 KB Output is correct
6 Correct 3 ms 4308 KB Output is correct
7 Correct 4 ms 4308 KB Output is correct
8 Correct 2 ms 4308 KB Output is correct
9 Correct 3 ms 4296 KB Output is correct
10 Correct 2 ms 4308 KB Output is correct
11 Correct 2 ms 4296 KB Output is correct
12 Correct 2 ms 4308 KB Output is correct
13 Correct 3 ms 4296 KB Output is correct
14 Correct 2 ms 4308 KB Output is correct
15 Correct 3 ms 4308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4308 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 3 ms 4308 KB Output is correct
4 Correct 3 ms 4308 KB Output is correct
5 Correct 3 ms 4308 KB Output is correct
6 Correct 3 ms 4308 KB Output is correct
7 Correct 4 ms 4308 KB Output is correct
8 Correct 2 ms 4308 KB Output is correct
9 Correct 3 ms 4296 KB Output is correct
10 Correct 2 ms 4308 KB Output is correct
11 Correct 2 ms 4296 KB Output is correct
12 Correct 2 ms 4308 KB Output is correct
13 Correct 3 ms 4296 KB Output is correct
14 Correct 2 ms 4308 KB Output is correct
15 Correct 3 ms 4308 KB Output is correct
16 Correct 2 ms 4308 KB Output is correct
17 Correct 3 ms 4296 KB Output is correct
18 Correct 3 ms 4308 KB Output is correct
19 Correct 3 ms 4300 KB Output is correct
20 Correct 2 ms 4308 KB Output is correct
21 Correct 3 ms 4300 KB Output is correct
22 Correct 4 ms 4308 KB Output is correct
23 Correct 3 ms 4296 KB Output is correct
24 Correct 3 ms 4308 KB Output is correct
25 Correct 3 ms 4296 KB Output is correct
26 Correct 3 ms 4308 KB Output is correct
27 Correct 3 ms 4304 KB Output is correct
28 Correct 3 ms 4304 KB Output is correct
29 Correct 3 ms 4308 KB Output is correct
30 Correct 2 ms 4308 KB Output is correct
31 Correct 3 ms 4308 KB Output is correct
32 Correct 3 ms 4308 KB Output is correct
33 Correct 3 ms 4300 KB Output is correct
34 Correct 3 ms 4300 KB Output is correct
35 Correct 3 ms 4308 KB Output is correct
36 Correct 3 ms 4300 KB Output is correct
37 Correct 2 ms 4308 KB Output is correct
38 Correct 3 ms 4300 KB Output is correct
39 Correct 2 ms 4308 KB Output is correct
40 Correct 3 ms 4308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4308 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 3 ms 4308 KB Output is correct
4 Correct 3 ms 4308 KB Output is correct
5 Correct 3 ms 4308 KB Output is correct
6 Correct 3 ms 4308 KB Output is correct
7 Correct 4 ms 4308 KB Output is correct
8 Correct 2 ms 4308 KB Output is correct
9 Correct 3 ms 4296 KB Output is correct
10 Correct 2 ms 4308 KB Output is correct
11 Correct 2 ms 4296 KB Output is correct
12 Correct 2 ms 4308 KB Output is correct
13 Correct 3 ms 4296 KB Output is correct
14 Correct 2 ms 4308 KB Output is correct
15 Correct 3 ms 4308 KB Output is correct
16 Correct 2 ms 4308 KB Output is correct
17 Correct 3 ms 4296 KB Output is correct
18 Correct 3 ms 4308 KB Output is correct
19 Correct 3 ms 4300 KB Output is correct
20 Correct 2 ms 4308 KB Output is correct
21 Correct 3 ms 4300 KB Output is correct
22 Correct 4 ms 4308 KB Output is correct
23 Correct 3 ms 4296 KB Output is correct
24 Correct 3 ms 4308 KB Output is correct
25 Correct 3 ms 4296 KB Output is correct
26 Correct 3 ms 4308 KB Output is correct
27 Correct 3 ms 4304 KB Output is correct
28 Correct 3 ms 4304 KB Output is correct
29 Correct 3 ms 4308 KB Output is correct
30 Correct 2 ms 4308 KB Output is correct
31 Correct 3 ms 4308 KB Output is correct
32 Correct 3 ms 4308 KB Output is correct
33 Correct 3 ms 4300 KB Output is correct
34 Correct 3 ms 4300 KB Output is correct
35 Correct 3 ms 4308 KB Output is correct
36 Correct 3 ms 4300 KB Output is correct
37 Correct 2 ms 4308 KB Output is correct
38 Correct 3 ms 4300 KB Output is correct
39 Correct 2 ms 4308 KB Output is correct
40 Correct 3 ms 4308 KB Output is correct
41 Correct 4 ms 4692 KB Output is correct
42 Correct 4 ms 4700 KB Output is correct
43 Correct 4 ms 4692 KB Output is correct
44 Correct 5 ms 4680 KB Output is correct
45 Correct 7 ms 4824 KB Output is correct
46 Correct 6 ms 4692 KB Output is correct
47 Correct 10 ms 4812 KB Output is correct
48 Correct 9 ms 4824 KB Output is correct
49 Correct 12 ms 4800 KB Output is correct
50 Correct 12 ms 4800 KB Output is correct
51 Correct 16 ms 4820 KB Output is correct
52 Correct 16 ms 4820 KB Output is correct
53 Correct 9 ms 4820 KB Output is correct
54 Correct 9 ms 4820 KB Output is correct
55 Correct 8 ms 4816 KB Output is correct
56 Correct 8 ms 4820 KB Output is correct
57 Correct 9 ms 4820 KB Output is correct
58 Correct 9 ms 4820 KB Output is correct
59 Correct 10 ms 4820 KB Output is correct
60 Correct 10 ms 4820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1663 ms 8276 KB Output is correct
2 Correct 1640 ms 8344 KB Output is correct
3 Correct 1660 ms 8276 KB Output is correct
4 Correct 1642 ms 8408 KB Output is correct
5 Correct 1623 ms 8276 KB Output is correct
6 Correct 1613 ms 8384 KB Output is correct
7 Correct 1592 ms 8280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 21 ms 6680 KB Output is correct
6 Correct 101 ms 7280 KB Output is correct
7 Correct 377 ms 8156 KB Output is correct
8 Correct 808 ms 8396 KB Output is correct
9 Correct 1416 ms 8272 KB Output is correct
10 Correct 708 ms 8268 KB Output is correct
11 Correct 2 ms 4308 KB Output is correct
12 Correct 167 ms 7436 KB Output is correct
13 Correct 147 ms 7392 KB Output is correct
14 Correct 140 ms 7480 KB Output is correct
15 Correct 816 ms 8264 KB Output is correct
16 Correct 777 ms 8284 KB Output is correct
17 Correct 750 ms 8268 KB Output is correct
18 Correct 1672 ms 8276 KB Output is correct
19 Correct 1552 ms 8276 KB Output is correct
20 Correct 1482 ms 8276 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 3 ms 4308 KB Output is correct
25 Correct 3 ms 4308 KB Output is correct
26 Correct 3 ms 4308 KB Output is correct
27 Correct 4 ms 4308 KB Output is correct
28 Correct 2 ms 4308 KB Output is correct
29 Correct 3 ms 4296 KB Output is correct
30 Correct 2 ms 4308 KB Output is correct
31 Correct 2 ms 4296 KB Output is correct
32 Correct 2 ms 4308 KB Output is correct
33 Correct 3 ms 4296 KB Output is correct
34 Correct 2 ms 4308 KB Output is correct
35 Correct 3 ms 4308 KB Output is correct
36 Correct 2 ms 4308 KB Output is correct
37 Correct 3 ms 4296 KB Output is correct
38 Correct 3 ms 4308 KB Output is correct
39 Correct 3 ms 4300 KB Output is correct
40 Correct 2 ms 4308 KB Output is correct
41 Correct 3 ms 4300 KB Output is correct
42 Correct 4 ms 4308 KB Output is correct
43 Correct 3 ms 4296 KB Output is correct
44 Correct 3 ms 4308 KB Output is correct
45 Correct 3 ms 4296 KB Output is correct
46 Correct 3 ms 4308 KB Output is correct
47 Correct 3 ms 4304 KB Output is correct
48 Correct 3 ms 4304 KB Output is correct
49 Correct 3 ms 4308 KB Output is correct
50 Correct 2 ms 4308 KB Output is correct
51 Correct 3 ms 4308 KB Output is correct
52 Correct 3 ms 4308 KB Output is correct
53 Correct 3 ms 4300 KB Output is correct
54 Correct 3 ms 4300 KB Output is correct
55 Correct 3 ms 4308 KB Output is correct
56 Correct 3 ms 4300 KB Output is correct
57 Correct 2 ms 4308 KB Output is correct
58 Correct 3 ms 4300 KB Output is correct
59 Correct 2 ms 4308 KB Output is correct
60 Correct 3 ms 4308 KB Output is correct
61 Correct 4 ms 4692 KB Output is correct
62 Correct 4 ms 4700 KB Output is correct
63 Correct 4 ms 4692 KB Output is correct
64 Correct 5 ms 4680 KB Output is correct
65 Correct 7 ms 4824 KB Output is correct
66 Correct 6 ms 4692 KB Output is correct
67 Correct 10 ms 4812 KB Output is correct
68 Correct 9 ms 4824 KB Output is correct
69 Correct 12 ms 4800 KB Output is correct
70 Correct 12 ms 4800 KB Output is correct
71 Correct 16 ms 4820 KB Output is correct
72 Correct 16 ms 4820 KB Output is correct
73 Correct 9 ms 4820 KB Output is correct
74 Correct 9 ms 4820 KB Output is correct
75 Correct 8 ms 4816 KB Output is correct
76 Correct 8 ms 4820 KB Output is correct
77 Correct 9 ms 4820 KB Output is correct
78 Correct 9 ms 4820 KB Output is correct
79 Correct 10 ms 4820 KB Output is correct
80 Correct 10 ms 4820 KB Output is correct
81 Correct 1663 ms 8276 KB Output is correct
82 Correct 1640 ms 8344 KB Output is correct
83 Correct 1660 ms 8276 KB Output is correct
84 Correct 1642 ms 8408 KB Output is correct
85 Correct 1623 ms 8276 KB Output is correct
86 Correct 1613 ms 8384 KB Output is correct
87 Correct 1592 ms 8280 KB Output is correct
88 Correct 26 ms 6612 KB Output is correct
89 Correct 27 ms 6748 KB Output is correct
90 Correct 113 ms 7264 KB Output is correct
91 Correct 110 ms 7244 KB Output is correct
92 Correct 416 ms 8424 KB Output is correct
93 Correct 419 ms 8232 KB Output is correct
94 Correct 924 ms 8392 KB Output is correct
95 Correct 908 ms 8252 KB Output is correct
96 Correct 1291 ms 8344 KB Output is correct
97 Correct 1292 ms 8280 KB Output is correct
98 Correct 792 ms 8276 KB Output is correct
99 Correct 787 ms 8328 KB Output is correct
100 Correct 795 ms 8404 KB Output is correct
101 Correct 787 ms 8268 KB Output is correct
102 Correct 800 ms 8280 KB Output is correct
103 Correct 793 ms 8212 KB Output is correct
104 Correct 799 ms 8256 KB Output is correct
105 Correct 786 ms 8276 KB Output is correct