답안 #549708

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
549708 2022-04-16T10:52:06 Z cpp219 Let's Win the Election (JOI22_ho_t3) C++17
72 / 100
45 ms 3812 KB
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define debug(y) cout<<y,exit(0)
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 500 + 9;
const ll inf = 1e18 + 7;

ld ans = inf*1.0,dp[N][N];
ll n,k,collab;
LL a[N];

bool lf(LL x,LL y){
    return x.sc < y.sc;
}

ld cal(ll mid){
    for (ll i = 1;i <= n;i++)
        for (ll j = 0;j <= i;j++){
            dp[i][j] = inf;
            if (i - j - 1 >= mid) dp[i][j] = dp[i - 1][j];
            else dp[i][j] = dp[i - 1][j] + (ld)a[i].sc/((ld)i - j);
            if (j) dp[i][j] = min(dp[i][j],dp[i - 1][j - 1] + (ld)a[i].fs/((ld)mid + 1));
        }
    ld tmp = inf;
    for (ll i = k - mid;i <= n;i++)
        if (n - i >= mid) tmp = min(tmp,dp[n][i]);
    return tmp;
}

int main(){
    ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        //freopen(task".out","w",stdout);
    }
    cin>>n>>k;
    for (ll i = 1;i <= n;i++){
        cin>>a[i].fs>>a[i].sc;
        collab += (a[i].sc != -1);
        if (a[i].sc == -1) a[i].sc = inf;
    }
    sort(a + 1,a + n + 1,lf);
    ll l = 0,h = min(k,collab);
    while(l <= h){
        ll mid = (l + h)/2;
        if (cal(mid) < cal(mid + 1)) h = mid - 1;
        else l = mid + 1;
    }
    //debug(h);
    cout<<fixed<<setprecision(6)<<cal(l);
}
/// be confident

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 6 ms 3796 KB Output is correct
6 Correct 6 ms 3796 KB Output is correct
7 Correct 6 ms 3796 KB Output is correct
8 Correct 6 ms 3796 KB Output is correct
9 Correct 6 ms 3796 KB Output is correct
10 Correct 8 ms 3784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 6 ms 3796 KB Output is correct
6 Correct 6 ms 3796 KB Output is correct
7 Correct 6 ms 3796 KB Output is correct
8 Correct 6 ms 3796 KB Output is correct
9 Correct 6 ms 3796 KB Output is correct
10 Correct 8 ms 3784 KB Output is correct
11 Incorrect 1 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 416 KB Output is correct
4 Correct 0 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 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 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 340 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 416 KB Output is correct
4 Correct 0 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 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 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 340 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 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 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 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 324 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 324 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 336 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 328 KB Output is correct
38 Correct 1 ms 416 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 416 KB Output is correct
4 Correct 0 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 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 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 340 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 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 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 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 324 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 324 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 336 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 328 KB Output is correct
38 Correct 1 ms 416 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 716 KB Output is correct
42 Correct 2 ms 724 KB Output is correct
43 Correct 2 ms 724 KB Output is correct
44 Correct 1 ms 724 KB Output is correct
45 Correct 2 ms 712 KB Output is correct
46 Correct 2 ms 724 KB Output is correct
47 Correct 2 ms 724 KB Output is correct
48 Correct 2 ms 724 KB Output is correct
49 Correct 2 ms 724 KB Output is correct
50 Correct 2 ms 708 KB Output is correct
51 Correct 2 ms 724 KB Output is correct
52 Correct 3 ms 712 KB Output is correct
53 Correct 2 ms 708 KB Output is correct
54 Correct 2 ms 724 KB Output is correct
55 Correct 2 ms 724 KB Output is correct
56 Correct 2 ms 712 KB Output is correct
57 Correct 2 ms 724 KB Output is correct
58 Correct 2 ms 724 KB Output is correct
59 Correct 2 ms 724 KB Output is correct
60 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 3796 KB Output is correct
2 Correct 40 ms 3796 KB Output is correct
3 Correct 34 ms 3812 KB Output is correct
4 Correct 32 ms 3796 KB Output is correct
5 Correct 44 ms 3796 KB Output is correct
6 Correct 34 ms 3808 KB Output is correct
7 Correct 45 ms 3796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 6 ms 3796 KB Output is correct
6 Correct 6 ms 3796 KB Output is correct
7 Correct 6 ms 3796 KB Output is correct
8 Correct 6 ms 3796 KB Output is correct
9 Correct 6 ms 3796 KB Output is correct
10 Correct 8 ms 3784 KB Output is correct
11 Incorrect 1 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -