제출 #660487

#제출 시각아이디문제언어결과실행 시간메모리
660487SansPapyrus683Mobile (BOI12_mobile)C++17
0 / 100
1089 ms32588 KiB
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>

// #include "debugging.hpp"

using std::cout;
using std::endl;
using std::vector;
using Point = std::pair<double, double>;

constexpr int PRECISION = 4;

double dist(const Point& p1, const Point& p2) {
    double dx = p1.first - p2.first;
    double dy = p1.second - p2.second;
    return std::sqrt(dx * dx + dy * dy);
}

double min_dist(double road_pos, const vector<Point>& towers) {
    double ret = dist({road_pos, 0}, towers[0]);
    for (int i = 1; i < towers.size(); i++) {
        ret = std::max(ret, dist({road_pos, 0}, towers[i]));
    }
    return ret;
}

/**
 * https://oj.uz/problem/view/BOI12_mobile
 * 2 10
 * 0 0
 * 11 1 should output something close to 5.545455
 */
int main() {
    int tower_num;
    int road_len;
    std::cin >> tower_num >> road_len;
    
    vector<Point> towers(tower_num);
    for (Point& t : towers) {
        std::cin >> t.first >> t.second;
    }

    long long div_by = std::pow(10, PRECISION);
    long long lo = 0;
    long long hi = (long long) road_len * div_by;
    while (lo <= hi) {
        long long mid = (lo + hi) / 2;  // this shouldn't overflow
        long long next = mid + 1;
        double mid_val = min_dist((double) mid / div_by, towers);
        double next_val = min_dist((double) next / div_by, towers);
        if (mid_val < next_val) {
            hi = mid - 1;
        } else {
            lo = mid + 1;
        }
    }

    cout << std::fixed << std::setprecision(PRECISION)
         << (double) lo / div_by << endl;
}

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

mobile.cpp: In function 'double min_dist(double, const std::vector<std::pair<double, double> >&)':
mobile.cpp:24:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<double, double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for (int i = 1; i < towers.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...