Submission #787091

# Submission time Handle Problem Language Result Execution time Memory
787091 2023-07-18T19:41:55 Z JoenPoenMan Rice Hub (IOI11_ricehub) C++17
68 / 100
1000 ms 1680 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> crs;
    stack<ii> removed;
    long long cost = 0;
    int i = 0;
    int best = 0;
    long long dc = 0;
    unsigned int distTillNext = 1e8;
    for (int x = 1; x <= L && (i < R || dc < 0); x++)
    {
        while (!removed.empty() && removed.top().first + x - removed.top().second <= B - cost) {
            crs.insert(crs.begin(), removed.top().first + x - removed.top().second);
            cost += crs[0];
            dc++;
            removed.pop();
        }
        while (i < R && cost + (X[i]-x) <= B) {
            crs.push_back(x - X[i]);
            cost += X[i]-x;
            dc--;
            i++;
        }
        while (crs.size() && i < R && (X[i]-x) <= crs[0]) {
            cost -= crs[0];
            removed.push({crs[0], x});
            crs.erase(crs.begin());
            crs.push_back(x - X[i]);
            cost += X[i]-x;
            dc -= 2;
            i++;
        }
        while (i < R && cost + (X[i]-x) <= B) {
            crs.push_back(x - X[i]);
            cost += X[i]-x;
            dc--;
            i++;
        }
        best = max(best, (int)crs.size());
        distTillNext = 1e8;
        bool first = false;
        for (int i = 0; i < crs.size(); i++) {
            if (crs[i] == 0) {
                dc += 2;
            } 
            if (crs[i] < 0 && !first) distTillNext = -crs[i]-1, first = true;
            crs[i]++;
        }
        
    

        cost += dc;
        while (cost > B) {
            cost -= crs[0];
            removed.push({crs[0], x});
            crs.erase(crs.begin());
            dc--;
        }
        unsigned int dx = 1e8;
        if (i < R && X[i]-(x+1) <= B-cost) dx = 0;
        if (i < R && dc-1 != 0) dx = ceil((B - cost - X[i] + (float)(x+1))/(dc-1));
        if (i < R && crs.size()) dx = min(dx, (unsigned int)((X[i]-(x+1)-crs[0]+1)/2));
        dx = min(dx, distTillNext);
        if (dc > 0) {
            dx = min(dx, (unsigned int)((B-cost)/dc));
        }
        x += dx;
        cost += dc * dx;
        for (int &el : crs) el += dx;
    }
    return best;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:54:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for (int i = 0; i < crs.size(); i++) {
      |                         ~~^~~~~~~~~~~~
# 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 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 316 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 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 0 ms 308 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 308 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 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 1 ms 316 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 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 312 KB Output is correct
4 Correct 1 ms 316 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 316 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 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 2 ms 212 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 19 ms 340 KB Output is correct
24 Correct 20 ms 412 KB Output is correct
25 Correct 28 ms 340 KB Output is correct
26 Correct 28 ms 340 KB Output is correct
27 Correct 27 ms 352 KB Output is correct
28 Correct 25 ms 392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 564 KB Output is correct
2 Correct 8 ms 672 KB Output is correct
3 Execution timed out 1059 ms 1680 KB Time limit exceeded
4 Halted 0 ms 0 KB -