Submission #787774

# Submission time Handle Problem Language Result Execution time Memory
787774 2023-07-19T12:29:12 Z JoenPoenMan Rice Hub (IOI11_ricehub) C++17
68 / 100
360 ms 1948 KB

#include "ricehub.h"
#include <bits/stdc++.h>

using namespace std;

#define ALL(arr) begin(arr), end(arr)
#define CONTAINS(arr, val) (find(ALL(arr), val) == end(arr))

typedef pair<int, int> ii;

int besthub(int R, int L, int X[], long long B)
{
    vector<int> linv;
    vector<int> rinv;
    stack<int> removed;
    int cost = 0;
    int ci = 1;
    int best = 0;
    for (int i = 0; i < R; i++) {
        ci = max(ci, i+1);
        int x = X[i];
        if (i > 0) {
            linv.push_back(X[i-1]);
            cost += linv.size() * (X[i] - X[i-1]);
            cost -= rinv.size() * (X[i] - X[i-1]);
            if (rinv.size()) rinv.erase(rinv.begin());
            if (X[i] == X[i-1]) continue;
        }

        while (cost > B) {
            cost -= x - linv[0];
            removed.push(linv[0]);
            linv.erase(linv.begin());
        }
        while (ci < R && cost + X[ci] - x <= B) {
            cost += X[ci] - x;
            rinv.push_back(X[ci]);
            ci++;
        }
        while (ci < R && linv.size() && x - linv[0] >= X[ci] - x) {
            cost -= x - linv[0];
            cost += X[ci] - x;
            removed.push(linv[0]);
            linv.erase(linv.begin());
            rinv.push_back(X[ci]);
            ci++;
        }

        while (ci < R && cost + X[ci] - x <= B) {
            cost += X[ci] - x;
            rinv.push_back(X[ci]);
            ci++;
        }
        while (!removed.empty() && x - removed.top() <= B - cost) {
            cost += x - removed.top();
            linv.insert(linv.begin(), removed.top());
            removed.pop();
        }
        best = max(best, (int)(linv.size() + rinv.size() + 1));

    }
    return best;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 216 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 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 2 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 346 ms 1736 KB Output is correct
4 Incorrect 360 ms 1948 KB Output isn't correct
5 Halted 0 ms 0 KB -