Submission #874794

# Submission time Handle Problem Language Result Execution time Memory
874794 2023-11-17T19:13:50 Z StefanL2005 Rice Hub (IOI11_ricehub) C++14
68 / 100
1000 ms 4956 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;
    }

    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;
            for (int j = left; j <= i; j++)
            {
                ll sum2 = Back_Sum[j] - Back_Sum[i] - (i - j) * (X[X.size() - 1] - X[i]);

                if (sum + sum2 <= B)
                {
                    part = j;
                    break;
                }
            }
             // functie pentru cautare binara stanga
            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;
}

Compilation message

ricehub.cpp: In function 'int cautare_binara(int, int, int, long long int, std::vector<long long int>&, std::vector<int>&)':
ricehub.cpp:49:13: warning: unused variable 'm' [-Wunused-variable]
   49 |         int m = (c1 + c2) / 2;
      |             ^
ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:93:48: warning: 'part' may be used uninitialized in this function [-Wmaybe-uninitialized]
   93 |             if (part - 1 >= 0 && X[i] - X[part - 1] < X[m] - X[i])
      |                                           ~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 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 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 496 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 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 1 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 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 360 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 4 ms 348 KB Output is correct
22 Correct 4 ms 580 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 4 ms 348 KB Output is correct
25 Correct 3 ms 348 KB Output is correct
26 Correct 5 ms 348 KB Output is correct
27 Correct 18 ms 348 KB Output is correct
28 Correct 18 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 860 KB Output is correct
2 Correct 6 ms 860 KB Output is correct
3 Correct 23 ms 4956 KB Output is correct
4 Execution timed out 1063 ms 4956 KB Time limit exceeded
5 Halted 0 ms 0 KB -