Submission #874964

# Submission time Handle Problem Language Result Execution time Memory
874964 2023-11-18T10:46:22 Z StefanL2005 Rice Hub (IOI11_ricehub) C++14
68 / 100
96 ms 5980 KB
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
#define ll long long


int search_end(int c1, int c2, int i, ll B, vector<ll> &Front_Sum, vector<ll> &Back_Sum, vector<int> &X, int CASE)
{
    int ans = i;

    while (c1 <= c2)
    {
        int m = (c1 + c2) / 2;

        switch(CASE)
        {
            case 1:{
                if (Front_Sum[m] - Front_Sum[i] - (m - i) * (X[i] - X[0]) > B)
                    c2 = m - 1;
                else
                {
                    ans = m;
                    c1 = m + 1;
                }
                break;
            }

            case 2:{
                if (Back_Sum[m] - Back_Sum[i] - (i - m) * (X[X.size() - 1] - X[i]) > B)
                    c1 = m + 1;
                else
                {   
                    ans = m;
                    c2 = m - 1;
                }
                break;
            }
        }
    }
    return ans;
}

int cautare_binara(int c1, int c2, int i, ll B, vector<ll> &Back_Sum, vector<int> &X)
{
    int ans = i;

    while (c1 <= c2)
    {
        int m = (c1 + c2) / 2;

        ll sum2 = Back_Sum[m] - Back_Sum[i] - (i - m) * (X[X.size() - 1] - X[i]);
        
        if (sum2 > B)
            c1 = m + 1;
        else
        {
            ans = m;
            c2 = m - 1;
        }
    }

    return ans;
}
int besthub(int R, int L, int V[], ll B)
{
    vector<int> X(R);
    vector<int> Best(R);
    vector<ll> Front_Sum(R, 0);
    vector<ll> Back_Sum(R, 0);
    for (int i = 0; i < R; i++)
        X[i] = V[i];
    
    for (int i = 1; i < R; i++)
        Front_Sum[i] = Front_Sum[i - 1] + X[i] - X[0];
    for (int i = R - 2; i >= 0; i--)
        Back_Sum [i]= Back_Sum[i + 1] + X[R - 1] - X[i];

    for (int i = 0; i < R; i++)
    {
        int left = search_end(0, i, i, B, Front_Sum, Back_Sum, X, 2);
        int right = search_end(i, R - 1, i, B, Front_Sum, Back_Sum, X, 1);

        int c1 = i, c2 = right, ans = 1;

        while (c1 <= c2)
        {
            int m = (c1 + c2) / 2;
            ll sum =  Front_Sum[m] - Front_Sum[i] - (m - i) * (X[i] - X[0]);   
            
            int part = cautare_binara(left, i, i, B - sum, Back_Sum, X);
            ans = max(ans, m - part + 1);
            
            if (part - 1 >= 0 && X[i] - X[part - 1] < X[m] - X[i])
                c2 = m - 1; 
            else
                c1 = m + 1;
        }

        Best[i] = ans;
    }

    int Max = Best[0];
    for (int i = 0; i < R; i++)
        Max = max(Max, Best[i]);

    return Max;
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 448 KB Output is correct
10 Correct 0 ms 356 KB Output is correct
11 Correct 0 ms 352 KB Output is correct
12 Correct 0 ms 352 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 352 KB Output is correct
15 Correct 1 ms 352 KB Output is correct
16 Correct 1 ms 352 KB Output is correct
17 Correct 0 ms 352 KB Output is correct
18 Correct 0 ms 352 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 448 KB Output is correct
26 Correct 0 ms 352 KB Output is correct
27 Correct 1 ms 352 KB Output is correct
28 Correct 1 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 356 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 356 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 1 ms 356 KB Output is correct
9 Correct 0 ms 352 KB Output is correct
10 Correct 1 ms 352 KB Output is correct
11 Correct 1 ms 352 KB Output is correct
12 Correct 1 ms 352 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 352 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 352 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 352 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 484 KB Output is correct
23 Correct 3 ms 604 KB Output is correct
24 Correct 3 ms 612 KB Output is correct
25 Correct 3 ms 604 KB Output is correct
26 Correct 3 ms 460 KB Output is correct
27 Correct 3 ms 604 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1116 KB Output is correct
2 Correct 5 ms 968 KB Output is correct
3 Correct 69 ms 5980 KB Output is correct
4 Incorrect 96 ms 5976 KB Output isn't correct
5 Halted 0 ms 0 KB -