Submission #743309

# Submission time Handle Problem Language Result Execution time Memory
743309 2023-05-17T09:44:22 Z vjudge1 Rice Hub (IOI11_ricehub) C++17
0 / 100
13 ms 1748 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;

int besthub(int R, int L, int X[], long long B)
{
    int mid = X[R / 2];
    int left = (R / 2) - 1;
    int right = (R / 2) + 1;
    int possible = 1;
    int curcost = 0;
    bool breakleft = false;
    bool breakright = false;
    while (!breakleft || !breakright)
    {
        int disleft, disright;
        if (left >= 0)
            disleft = mid - X[left];
        else
            breakleft = 1;
        if (right < R)
            disright = X[right] - mid;
        else
            breakright = 1;
        if (disleft > disright && !breakleft)
        {
            if (disleft + curcost <= B)
            {
                possible++;
                curcost += disleft;
                left--;
            }
            else
            {
                breakleft = true;
            }
            if (disright + curcost <= B)
            {
                possible++;
                curcost += disright;
                right++;
            }
            else
            {
                breakright = true;
            }
        }
        else
        {
            if (disright + curcost <= B)
            {
                possible++;
                curcost += disright;
                right++;
            }
            else
            {
                breakright = true;
            }
            if (disleft + curcost <= B)
            {
                possible++;
                curcost += disleft;
                left--;
            }
            else
            {
                breakleft = true;
            }
        }
    }
    return possible;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:37:26: warning: 'disright' may be used uninitialized in this function [-Wmaybe-uninitialized]
   37 |             if (disright + curcost <= B)
      |                 ~~~~~~~~~^~~~~~~~~
ricehub.cpp:27:25: warning: 'disleft' may be used uninitialized in this function [-Wmaybe-uninitialized]
   27 |             if (disleft + curcost <= B)
      |                 ~~~~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 236 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 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 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 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 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 3 ms 500 KB Output is correct
3 Incorrect 13 ms 1748 KB Output isn't correct
4 Halted 0 ms 0 KB -