Submission #660488

# Submission time Handle Problem Language Result Execution time Memory
660488 2022-11-22T04:18:41 Z SansPapyrus683 Mobile (BOI12_mobile) C++17
0 / 100
767 ms 15956 KB
#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<long long, long long>;

constexpr int PRECISION = 5;

long long dist_sq(const Point& p1, const Point& p2) {
    long long dx = p1.first - p2.first;
    long long dy = p1.second - p2.second;
    return dx * dx + dy * dy;
}

long long min_dist(long long road_pos, const vector<Point>& towers) {
    long long ret = dist_sq({road_pos, 0}, towers[0]);
    for (int i = 1; i < towers.size(); i++) {
        ret = std::max(ret, dist_sq({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;
    
    long long div_by = std::pow(10, PRECISION);
    vector<Point> towers(tower_num);
    for (Point& t : towers) {
        std::cin >> t.first >> t.second;
        t.first *= div_by;
        t.second *= div_by;
    }

    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;
        long long mid_val = min_dist(mid, towers);
        long long next_val = min_dist(next, towers);
        // cout << lo << ' ' << hi << endl;
        // cout << mid << ' ' << next << ' ' << mid_val << ' ' << next_val << endl;
        if (mid_val < next_val) {
            hi = mid - 1;
        } else {
            lo = mid + 1;
        }
    }

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

Compilation message

mobile.cpp: In function 'long long int min_dist(long long int, const std::vector<std::pair<long long int, long long int> >&)':
mobile.cpp:24:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for (int i = 1; i < towers.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 55 ms 1468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 47 ms 1512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 47 ms 1672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 73 ms 1852 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 81 ms 1856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 271 ms 8116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 379 ms 8120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 322 ms 9636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 451 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 381 ms 11244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 533 ms 11252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 421 ms 12756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 612 ms 12876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 558 ms 15956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 767 ms 15956 KB Output isn't correct
2 Halted 0 ms 0 KB -