Submission #245132

# Submission time Handle Problem Language Result Execution time Memory
245132 2020-07-05T14:42:43 Z A02 Rice Hub (IOI11_ricehub) C++14
49 / 100
31 ms 1792 KB
#include "ricehub.h"
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <fstream>

using namespace std;
int besthub(int R, int L, int X[], long long B)
{

    int left_best = 0;
    int right_best = 0;
    long long current_cost = 0;
    int current_field = 0;
    int current_max = 1;

    while (current_cost <= B){

        if (right_best == R - 1){
            break;
        }

        if (X[right_best + 1] - X[0] + current_cost > B){
            break;
        }

        right_best++;
        current_cost += X[right_best] - X[0];
        current_max++;
    }

    int best = current_max;

    while (current_field != R - 1){

        long long distance_moved = X[current_field + 1] - X[current_field];

        int to_right = right_best - current_field;
        int to_left =  current_field - left_best + 1;

        current_cost += to_left * distance_moved;
        current_cost -= to_right * distance_moved;

        if (current_field == right_best){
            right_best++;
            current_max++;
        }
        current_field++;

        while (current_cost > B){
            current_cost -= (X[current_field] - X[left_best]);
            current_max--;
            left_best++;
        }


        while (right_best != R - 1){

            if (current_cost + X[right_best + 1] - X[current_field] <= B){
                current_cost += (X[right_best + 1] - X[current_field]);
                right_best++;
                current_max++;
            } else {
                if (X[current_field] - X[left_best] > X[right_best] - X[current_field]){
                    current_cost -= (X[current_field] - X[left_best]);
                    current_cost += (X[right_best + 1] - X[current_field]);
                    right_best++;
                    left_best++;
                }  else {
                break;
            }
            }

        }

        best = max(current_max, best);
    }

    //cout << X[0] << ' ' << X[1] << ' ' << X[2] << endl;
    //cout << best << ' ' << current_cost << ' ' << right_best << ' ' << B <<  endl;
    return best;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 372 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 256 KB Output is correct
27 Incorrect 5 ms 256 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Incorrect 5 ms 384 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 512 KB Output is correct
2 Correct 7 ms 512 KB Output is correct
3 Correct 21 ms 1792 KB Output is correct
4 Correct 22 ms 1792 KB Output is correct
5 Correct 12 ms 896 KB Output is correct
6 Correct 12 ms 896 KB Output is correct
7 Correct 19 ms 1536 KB Output is correct
8 Correct 20 ms 1536 KB Output is correct
9 Correct 12 ms 768 KB Output is correct
10 Correct 12 ms 768 KB Output is correct
11 Correct 23 ms 1792 KB Output is correct
12 Correct 24 ms 1792 KB Output is correct
13 Correct 13 ms 896 KB Output is correct
14 Correct 13 ms 896 KB Output is correct
15 Correct 18 ms 1408 KB Output is correct
16 Correct 19 ms 1408 KB Output is correct
17 Correct 21 ms 1664 KB Output is correct
18 Correct 22 ms 1664 KB Output is correct
19 Correct 31 ms 1784 KB Output is correct
20 Correct 23 ms 1788 KB Output is correct