Submission #872500

# Submission time Handle Problem Language Result Execution time Memory
872500 2023-11-13T08:33:05 Z StefanL2005 Rice Hub (IOI11_ricehub) C++14
0 / 100
10 ms 4752 KB
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
#define ll long long


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

    ll sum = dp[0];
    int right = R, left = 0;
    for (int i = 1; i < R; i++)
    {
        right--;
        left++;
        if (X[i] == X[i - 1])
        {
            dp[i] = dp[i - 1];
            continue;
        }

        int dif = X[i] - X[i - 1];

        sum = sum - dif * right + dif * left;
        dp[i] = sum;
    }

    ll Min = dp[0]; int poz = 0;
    for (int i = 0; i < R; i++)
        if (dp[i] < Min)
        {
            Min = dp[i];
            poz = i;
        }
    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;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 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 600 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 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 0 ms 348 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 348 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 348 KB Output is correct
19 Incorrect 1 ms 348 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 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
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 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Incorrect 0 ms 348 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 10 ms 3672 KB Output is correct
4 Correct 10 ms 4752 KB Output is correct
5 Correct 5 ms 3420 KB Output is correct
6 Correct 5 ms 3420 KB Output is correct
7 Correct 10 ms 4444 KB Output is correct
8 Correct 9 ms 4440 KB Output is correct
9 Correct 5 ms 3420 KB Output is correct
10 Correct 4 ms 3416 KB Output is correct
11 Correct 10 ms 4688 KB Output is correct
12 Incorrect 10 ms 4704 KB Output isn't correct
13 Halted 0 ms 0 KB -