Submission #787776

# Submission time Handle Problem Language Result Execution time Memory
787776 2023-07-19T12:29:52 Z JoenPoenMan Rice Hub (IOI11_ricehub) C++17
100 / 100
477 ms 1836 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;
    long long 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 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 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 1 ms 212 KB Output is correct
7 Correct 1 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 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 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 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 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 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 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 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 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 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 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 2 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 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 2 ms 468 KB Output is correct
3 Correct 365 ms 1744 KB Output is correct
4 Correct 477 ms 1744 KB Output is correct
5 Correct 6 ms 656 KB Output is correct
6 Correct 5 ms 708 KB Output is correct
7 Correct 348 ms 1764 KB Output is correct
8 Correct 440 ms 1752 KB Output is correct
9 Correct 16 ms 724 KB Output is correct
10 Correct 17 ms 700 KB Output is correct
11 Correct 354 ms 1836 KB Output is correct
12 Correct 461 ms 1732 KB Output is correct
13 Correct 5 ms 596 KB Output is correct
14 Correct 7 ms 596 KB Output is correct
15 Correct 201 ms 1652 KB Output is correct
16 Correct 247 ms 1204 KB Output is correct
17 Correct 280 ms 1728 KB Output is correct
18 Correct 343 ms 1300 KB Output is correct
19 Correct 321 ms 1800 KB Output is correct
20 Correct 401 ms 1728 KB Output is correct