Submission #115282

# Submission time Handle Problem Language Result Execution time Memory
115282 2019-06-06T13:48:26 Z oolimry Rice Hub (IOI11_ricehub) C++14
68 / 100
25 ms 2560 KB
#include "ricehub.h"
#include <bits/stdc++.h>

using namespace std;

int besthub(int R, int L, int X[], long long B)
{
    long long pre[R];
    pre[0] = X[0];
    for(int i = 1;i < R;i++){
        pre[i] = pre[i-1] + X[i];
    }
    long long ans = 0;


    for(int i = 0;i < R;i++){
        int pos = X[i];
        long long low = 0;
        long long high = R;
        while(true){
            if(low == high - 1) break;
            int s = (low + high) / 2;

            int l  = i - s;
            int u = i + s;
            if(l < 0 || u >= R){
                high = s;
                continue;
            }

            long long sum = 0ll;
            sum += pre[i];
            if(l > 0) sum -= pre[l-1];
            sum = (s + 1) * pos - sum;
            sum += pre[u];
            sum -= pre[i];
            sum -= pos * s;
            if(sum > B){
                high = s;
            }
            else{
                low = s;
            }
        }
        ans = max(ans, 2 * low + 1);
        int l = i - low;
        int u = i + low;
        long long sum = 0ll;
        sum += pre[i];
        if(l > 0) sum -= pre[l-1];
        sum = (low + 1) * pos - sum;
        sum += pre[u];
        sum -= pre[i];
        sum -= pos * low;
        if(l > 0 && sum + abs(pos - X[l-1]) <= B){
            ans = max(ans, 2 * low + 2);
        }
        if(u + 1 < R && sum + abs(pos - X[u+1]) <= B){
            ans = max(ans, 2 * low + 2);
        }
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 412 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 23 ms 1536 KB Output is correct
4 Correct 23 ms 1528 KB Output is correct
5 Correct 10 ms 896 KB Output is correct
6 Correct 11 ms 964 KB Output is correct
7 Correct 21 ms 1536 KB Output is correct
8 Correct 21 ms 2276 KB Output is correct
9 Correct 11 ms 1152 KB Output is correct
10 Correct 10 ms 1152 KB Output is correct
11 Correct 25 ms 2560 KB Output is correct
12 Correct 25 ms 2552 KB Output is correct
13 Incorrect 11 ms 1280 KB Output isn't correct
14 Halted 0 ms 0 KB -