제출 #784701

#제출 시각아이디문제언어결과실행 시간메모리
784701BoasFinding Routers (IOI20_routers)C++17
39 / 100
1 ms340 KiB
#include "routers.h"

using namespace std;
// l is length
// n is number of routers
// q is max uses of detector
vector<int> find_routers(int l, int n, int q)
{
  vector<int> ans(n); // distance of each router i to the origin
  if (n == 2)
  {
    // find position of switch (first point where i = 1) using binary search
    int min = 2;
    int max = (l / 2) + 1;
    while (max - min > 0)
    {
      int k = (max + min) / 2;
      int i = use_detector(k);
      if (i == 0)
      {
        min = k + 1;
      }
      else
      {
        max = k;
      }
    }
    if (1 >= ans.size() || 1 < 0)
      throw;
    ans[1] = min + max - 2;
  }
  else
  {
    for (int i = 1; i < n; i++)
    {
      if (i - 1 >= ans.size() || i - 1 < 0)
        throw;
      int locMin = ans[i - 1] + 2;
      int locMax = l - (2 * (n - 1 - i));
      int sMin = locMin;
      int sMax = (locMax / 2) + 1;
      while (sMax - sMin > 0)
      {
        int k = (sMax + sMin) / 2;
        int detectorIndex = use_detector(k);
        if (detectorIndex == 0)
        {
          sMin = k + 1;
        }
        else
        {
          sMax = k;
        }
      }
      if (i >= ans.size() || i < 0)
        throw;
      ans[i] = sMin + sMax - 2;
    }
  }
  return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

routers.cpp: In function 'std::vector<int> find_routers(int, int, int)':
routers.cpp:36:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |       if (i - 1 >= ans.size() || i - 1 < 0)
      |           ~~~~~~^~~~~~~~~~~~~
routers.cpp:55:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |       if (i >= ans.size() || i < 0)
      |           ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...