Submission #453667

# Submission time Handle Problem Language Result Execution time Memory
453667 2021-08-04T13:59:49 Z ponytail Rice Hub (IOI11_ricehub) C++17
100 / 100
22 ms 3276 KB
#include "ricehub.h"
#include "bits/stdc++.h"
#define int long long
using namespace std;
signed besthub(signed R, signed L, signed X[], int B){
    int N = R;
    int x[N+1], ps[N+1], ans=0, lb=1, rb=N;
    for(int i=1;i<=N;i++)x[i] = X[i-1];
    ps[0]=0;
    for(int i=1;i<=N;i++) ps[i]=ps[i-1]+x[i];
    while(lb<rb){
        int mid=(lb+rb+1)/2;
        bool ok=0;
        for(int i=1;i<=N-mid+1;i++){
            int idx=(2*i+mid-1)/2;
            int cost=x[idx]*(idx-i+1)-ps[idx]+ps[i-1]+ps[i+mid-1]-ps[idx-1]-x[idx]*(i+mid-idx);
            if(cost<=B) ok=1;
        }
        if(ok) lb=mid;
        else rb=mid-1;
    }
    return lb;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:7:26: warning: unused variable 'ans' [-Wunused-variable]
    7 |     int x[N+1], ps[N+1], ans=0, lb=1, rb=N;
      |                          ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 300 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 308 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 316 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 716 KB Output is correct
2 Correct 4 ms 716 KB Output is correct
3 Correct 19 ms 3268 KB Output is correct
4 Correct 16 ms 3276 KB Output is correct
5 Correct 8 ms 1612 KB Output is correct
6 Correct 9 ms 1568 KB Output is correct
7 Correct 18 ms 3032 KB Output is correct
8 Correct 14 ms 3020 KB Output is correct
9 Correct 8 ms 1448 KB Output is correct
10 Correct 8 ms 1484 KB Output is correct
11 Correct 16 ms 3276 KB Output is correct
12 Correct 22 ms 3268 KB Output is correct
13 Correct 12 ms 1612 KB Output is correct
14 Correct 9 ms 1612 KB Output is correct
15 Correct 12 ms 2488 KB Output is correct
16 Correct 12 ms 2452 KB Output is correct
17 Correct 15 ms 2944 KB Output is correct
18 Correct 16 ms 2980 KB Output is correct
19 Correct 15 ms 3148 KB Output is correct
20 Correct 15 ms 3076 KB Output is correct