Submission #469132

# Submission time Handle Problem Language Result Execution time Memory
469132 2021-08-30T21:28:25 Z Maurimuri80 Rice Hub (IOI11_ricehub) C++14
0 / 100
1000 ms 2008 KB
#include "ricehub.h"
#include <cmath>
#include <vector>
#include <iostream>
using namespace std;

int besthub(int R, int L, int X[], long long B)
{
  // cout << "Hello" << endl;
  vector<long long> ac(R + 1);
  ac[0] = 0;
  for (int i = 1; i <= R; i++)
  {
    ac[i] = ac[i - 1] + (long long)X[i - 1];
  }
  long long min, max, med;
  min = 1;
  max = R;
  // cout<<"Hello"<<endl;
  while (true)
  {
    if (min == max or min > max)
    {
      return min;
    }
    // med = ((min + max) / 2 )+1;
    cout<<med<<endl;
    //hallamos la mitad de los posible y no posible
    bool possible = false;
    for (int i = 0; i <= R - med; i++)
    {
      long long izq = i;
      long long der = i + med - 1;
      long long mid = (izq + der) / 2;
      long long aux = (mid - izq);
      long long aux2 = (der - mid);
      long long rm = X[mid];
      long long sum = ((aux - aux2) * rm) - (ac[mid] - ac[izq]) + (ac[der + 1] - ac[mid + 1]);
      if (sum <= B)
      {
        possible = true;
        break;
      }
    }
    if (possible == true)
    {
      min = med;
    }
    else
    {
      max = med - 1;
    }
  }
  return 1;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:16:23: warning: 'med' may be used uninitialized in this function [-Wmaybe-uninitialized]
   16 |   long long min, max, med;
      |                       ^~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 1632 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1084 ms 1860 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 1676 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1098 ms 2008 KB Time limit exceeded
2 Halted 0 ms 0 KB -