Submission #549713

# Submission time Handle Problem Language Result Execution time Memory
549713 2022-04-16T10:54:20 Z cpp219 Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
741 ms 3916 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);
    for (ll i = 0;i <= min(k,collab);i++) ans = min(ans,cal(i));
    cout<<fixed<<setprecision(6)<<ans; return 0;
    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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 284 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 3 ms 3796 KB Output is correct
6 Correct 4 ms 3796 KB Output is correct
7 Correct 3 ms 3796 KB Output is correct
8 Correct 3 ms 3796 KB Output is correct
9 Correct 3 ms 3796 KB Output is correct
10 Correct 3 ms 3796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 284 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 3 ms 3796 KB Output is correct
6 Correct 4 ms 3796 KB Output is correct
7 Correct 3 ms 3796 KB Output is correct
8 Correct 3 ms 3796 KB Output is correct
9 Correct 3 ms 3796 KB Output is correct
10 Correct 3 ms 3796 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 230 ms 3800 KB Output is correct
13 Correct 206 ms 3796 KB Output is correct
14 Correct 146 ms 3808 KB Output is correct
15 Correct 490 ms 3808 KB Output is correct
16 Correct 416 ms 3916 KB Output is correct
17 Correct 144 ms 3804 KB Output is correct
18 Correct 741 ms 3812 KB Output is correct
19 Correct 420 ms 3804 KB Output is correct
20 Correct 129 ms 3800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 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 0 ms 340 KB Output is correct
7 Correct 1 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 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 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 0 ms 340 KB Output is correct
3 Correct 0 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 0 ms 340 KB Output is correct
7 Correct 1 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 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 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 0 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 0 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 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 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 0 ms 340 KB Output is correct
3 Correct 0 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 0 ms 340 KB Output is correct
7 Correct 1 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 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 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 0 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 0 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 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 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 1 ms 724 KB Output is correct
42 Correct 1 ms 724 KB Output is correct
43 Correct 3 ms 724 KB Output is correct
44 Correct 2 ms 724 KB Output is correct
45 Correct 3 ms 724 KB Output is correct
46 Correct 5 ms 796 KB Output is correct
47 Correct 5 ms 792 KB Output is correct
48 Correct 7 ms 724 KB Output is correct
49 Correct 6 ms 724 KB Output is correct
50 Correct 5 ms 724 KB Output is correct
51 Correct 10 ms 800 KB Output is correct
52 Correct 9 ms 724 KB Output is correct
53 Correct 4 ms 724 KB Output is correct
54 Correct 4 ms 724 KB Output is correct
55 Correct 5 ms 724 KB Output is correct
56 Correct 5 ms 792 KB Output is correct
57 Correct 6 ms 724 KB Output is correct
58 Correct 7 ms 724 KB Output is correct
59 Correct 4 ms 724 KB Output is correct
60 Correct 7 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 719 ms 3800 KB Output is correct
2 Correct 715 ms 3800 KB Output is correct
3 Correct 702 ms 3804 KB Output is correct
4 Correct 727 ms 3800 KB Output is correct
5 Correct 698 ms 3916 KB Output is correct
6 Correct 708 ms 3916 KB Output is correct
7 Correct 711 ms 3808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 284 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 3 ms 3796 KB Output is correct
6 Correct 4 ms 3796 KB Output is correct
7 Correct 3 ms 3796 KB Output is correct
8 Correct 3 ms 3796 KB Output is correct
9 Correct 3 ms 3796 KB Output is correct
10 Correct 3 ms 3796 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 230 ms 3800 KB Output is correct
13 Correct 206 ms 3796 KB Output is correct
14 Correct 146 ms 3808 KB Output is correct
15 Correct 490 ms 3808 KB Output is correct
16 Correct 416 ms 3916 KB Output is correct
17 Correct 144 ms 3804 KB Output is correct
18 Correct 741 ms 3812 KB Output is correct
19 Correct 420 ms 3804 KB Output is correct
20 Correct 129 ms 3800 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 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 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 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 0 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 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 0 ms 340 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
54 Correct 0 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 0 ms 340 KB Output is correct
57 Correct 0 ms 340 KB Output is correct
58 Correct 0 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 1 ms 724 KB Output is correct
62 Correct 1 ms 724 KB Output is correct
63 Correct 3 ms 724 KB Output is correct
64 Correct 2 ms 724 KB Output is correct
65 Correct 3 ms 724 KB Output is correct
66 Correct 5 ms 796 KB Output is correct
67 Correct 5 ms 792 KB Output is correct
68 Correct 7 ms 724 KB Output is correct
69 Correct 6 ms 724 KB Output is correct
70 Correct 5 ms 724 KB Output is correct
71 Correct 10 ms 800 KB Output is correct
72 Correct 9 ms 724 KB Output is correct
73 Correct 4 ms 724 KB Output is correct
74 Correct 4 ms 724 KB Output is correct
75 Correct 5 ms 724 KB Output is correct
76 Correct 5 ms 792 KB Output is correct
77 Correct 6 ms 724 KB Output is correct
78 Correct 7 ms 724 KB Output is correct
79 Correct 4 ms 724 KB Output is correct
80 Correct 7 ms 724 KB Output is correct
81 Correct 719 ms 3800 KB Output is correct
82 Correct 715 ms 3800 KB Output is correct
83 Correct 702 ms 3804 KB Output is correct
84 Correct 727 ms 3800 KB Output is correct
85 Correct 698 ms 3916 KB Output is correct
86 Correct 708 ms 3916 KB Output is correct
87 Correct 711 ms 3808 KB Output is correct
88 Correct 89 ms 3796 KB Output is correct
89 Correct 72 ms 3804 KB Output is correct
90 Correct 176 ms 3796 KB Output is correct
91 Correct 172 ms 3808 KB Output is correct
92 Correct 356 ms 3820 KB Output is correct
93 Correct 349 ms 3796 KB Output is correct
94 Correct 528 ms 3820 KB Output is correct
95 Correct 520 ms 3824 KB Output is correct
96 Correct 630 ms 3808 KB Output is correct
97 Correct 634 ms 3804 KB Output is correct
98 Correct 503 ms 3796 KB Output is correct
99 Correct 489 ms 3808 KB Output is correct
100 Correct 509 ms 3804 KB Output is correct
101 Correct 489 ms 3808 KB Output is correct
102 Correct 492 ms 3808 KB Output is correct
103 Correct 491 ms 3808 KB Output is correct
104 Correct 489 ms 3812 KB Output is correct
105 Correct 507 ms 3916 KB Output is correct