제출 #1016295

#제출 시각아이디문제언어결과실행 시간메모리
1016295toast12Best Place (NOI17_bestplace)C++14
100 / 100
478 ms3156 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

vector<pair<int, int>> points;

ll find_dist(int x, int y) {
    ll ans = 0;
    for (int i = 0; i < (int)points.size(); i++) {
        ans += abs(x-points[i].first)+abs(y-points[i].second);
    }
    return ans;
}

int main() {
    int n;
    cin >> n;
    points.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> points[i].first >> points[i].second;
    }
    int l = 0, r = 1e9;
    int ansx = 0, ansy = 0;
    while (l < r) {
        int x = (l+r)/2;
        int t = 1e9, b = 0;
        ll dist1 = 1e15;
        while (b < t) {
            int y = (b+t)/2;
            int d1 = find_dist(x, y);
            int d2 = find_dist(x, y+1);
            dist1 = min(d1, d2);
            if (d1 < d2) 
                t = y;
            else 
                b = y+1;
        }
        ansy = t;
        ll dist2 = 1e15;
        b = 0, t = 1e9;
        while (b < t) {
            int y = (b+t)/2;
            int d1 = find_dist(x+1, y);
            int d2 = find_dist(x+1, y+1);
            dist2 = min(d1, d2);
            if (d1 < d2) 
                t = y;
            else 
                b = y+1;
        }
        if (dist1 < dist2)
            r = x;
        else {
            l = x+1;
            ansy = t;
        }
    }
    cout << r << ' ' << ansy << '\n';
    return 0;
}

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

bestplace.cpp: In function 'int main()':
bestplace.cpp:24:9: warning: unused variable 'ansx' [-Wunused-variable]
   24 |     int ansx = 0, ansy = 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...