Submission #335973

# Submission time Handle Problem Language Result Execution time Memory
335973 2020-12-14T12:33:36 Z aryan12 Rice Hub (IOI11_ricehub) C++17
68 / 100
1000 ms 3180 KB
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;

int besthub(int r, int l, int x[], long long b) {
    long long pre[r + 1], suf[r + 1];
    pre[0] = 0;
    pre[1] = 0;
    for(long long i = 2; i <= r; i++) {
        pre[i] = pre[i - 1] + x[i - 1];
    }
    suf[r] = 0;
    for(long long i = r - 1; i >= 1; i--) {
        suf[i] = suf[i + 1] + x[i + 1];
    }
    /*for(long long i = 1; i <= r; i++) {
        cout << pre[i] << " ";
    }
    cout << endl;
    for(long long i = r; i > 0; i--) {
        cout << suf[i] << " ";
    }
    cout << endl;*/
    long long ans = 1;
    for(long long i = 2; i <= r; i++) {
        long long left = 1, right = i, best = r;
        long long mid;
        while(left <= right) {
            long long LeftPoint = (left + right) / 2;
            long long OptimalField = (LeftPoint + i) / 2;
            long long cost = 0;
            for(long long j = LeftPoint; j <= i; j++) {
                cost += abs(x[j] - x[OptimalField]);
            }
            if(cost <= b) {
                right = LeftPoint - 1;
                best = LeftPoint;
            }
            else {
                left = LeftPoint + 1;
            }
        }
       // cout << i << " " << best << endl;
        ans = max(ans, i - best + 1);
    }
    int lol = ans;
    return lol;
}

/*int main() {
    //cout << "Input the number of rice fields" << endl;
    int r;
    cin >> r;
    //cout << "Input the maximum coordinate" << endl;
    int l;
    cin >> l;
    //cout << "Input r numbers, denoting the rice fields" << endl;
    int x[r + 1];
    for(int i = 1; i <= r; i++) {
        cin >> x[i];
    }
    //cout << "Input the budget" << endl;
    int b;
    cin >> b;
    cout << besthub(r, l, x, b) << endl;
}*/

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:27:19: warning: unused variable 'mid' [-Wunused-variable]
   27 |         long long mid;
      |                   ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 7 ms 388 KB Output is correct
4 Correct 76 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 9 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 3 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 5 ms 364 KB Output is correct
14 Correct 39 ms 364 KB Output is correct
15 Correct 38 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 36 ms 364 KB Output is correct
18 Correct 4 ms 364 KB Output is correct
19 Correct 6 ms 364 KB Output is correct
20 Correct 5 ms 364 KB Output is correct
21 Correct 29 ms 512 KB Output is correct
22 Correct 47 ms 396 KB Output is correct
23 Correct 154 ms 504 KB Output is correct
24 Correct 189 ms 396 KB Output is correct
25 Correct 138 ms 492 KB Output is correct
26 Correct 134 ms 492 KB Output is correct
27 Correct 110 ms 492 KB Output is correct
28 Correct 117 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 237 ms 900 KB Output is correct
2 Correct 245 ms 876 KB Output is correct
3 Execution timed out 1090 ms 3180 KB Time limit exceeded
4 Halted 0 ms 0 KB -