Submission #874057

# Submission time Handle Problem Language Result Execution time Memory
874057 2023-11-16T08:39:28 Z StefanL2005 Rice Hub (IOI11_ricehub) C++14
0 / 100
2 ms 604 KB
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
#define ll long long

int solve(int poz, int R, int B, vector<int> &X)
{
    int c1 = poz - 1, c2 = poz + 1;
    bool done_change = true;
    int nr = 1;
    while (done_change)
    {
        done_change = false;
        if (c1 < 0 && c2 >= R)
            break;

        if (c1 >= 0 && (c2 >= R || X[poz] - X[c1] <= X[c2] - X[poz]))
        {
            nr++; done_change = true;
            B -= (X[poz] - X[c1]);
            c1--;
        }
        else
            if (c2 < R && (c1 < 0 || X[c2] - X[poz] < X[poz] - X[c1]))
            {
                nr++; done_change = true;
                B -= (X[c2] - X[poz]);
                c2++;
            }

        if (B < 0)
        {
            nr--;
            done_change = false;
        }
    }
    return nr;
}

int besthub(int R, int L, int V[], ll B)
{
    vector<int> X(R);
    vector<int> Best(R);
    for (int i = 0; i < R; i++)
        X[i] = V[i];

    int c1 = 0, c2 = 0;
    ll sum = 0;
    while (c2 < R && sum + X[c2] - X[0] <= B)
    {
        sum += X[c2] - X[0];
        c2++;
    }

    c2--;
    Best[0] = c2 + 1;

    for (int i = 1; i < R; i++)
    {
        if (X[i] == X[i - 1])
        {
            Best[i] = Best[i - 1];
            if (c2 < i)
                c2 = i;
            continue;
        }

        sum += (i - c1) * (X[i] - X[i - 1]) - (c2 - (i - 1)) * (X[i] - X[i - 1]);

        if (c2 < i)
            c2 = i;
        while (sum > B)
        {
            sum -= X[i] - X[c1];
            c1++;
        }

        while (c2 + 1 < R && sum <= B)
        {
            sum += X[c2 + 1] - X[i];
            c2++;
        }

        while (c2 + 1 < R && X[c2 + 1] - X[i] <= X[i] - X[c1])
        {
            sum -= X[i] - X[c1];
            sum += X[c2 + 1] - X[i];
            c2++;
            c1++;
        }
        Best[i] = c2 - c1 + 1;
    }

    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 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -