結果

問題 No.1998 Manhattan Restaurant
ユーザー t98slider
提出日時 2022-07-02 20:24:33
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,065 bytes
コンパイル時間 2,234 ms
コンパイル使用メモリ 180,112 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-11-27 17:33:35
合計ジャッジ時間 4,947 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 27 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<pair<ll,ll>> a(n);
    for(auto &&p:a)cin >> p.first >> p.second;
    auto dist = [&](int i, int j){
        return abs(a[i].first - a[j].first) + abs(a[i].second - a[j].second);
    };
    vector<int> pos1(n), pos2;
    iota(pos1.begin(), pos1.end(), 0);
    pos2 = pos1;
    sort(pos1.begin(), pos1.end(), [&](int i, int j){
        return a[i].first + a[i].second < a[j].first + a[j].second;
    });
    sort(pos2.begin(), pos2.end(), [&](int i, int j){
        return a[i].first - a[i].second < a[j].first - a[j].second;
    });
    vector<ll> c(n), d(n);
    for(int i = 0; i < n; i++){
        c[i] = min(max(dist(i, pos1[0]), dist(i, pos2[0])), max(dist(i, pos1[n - 1]), dist(i, pos2[n - 1])));
        d[i] = min(max(dist(i, pos1[0]), dist(i, pos2[n - 1])), max(dist(i, pos1[n - 1]), dist(i, pos2[0])));
    }
    ll ans = *max_element(c.begin(), c.end());
    ans = min(ans, *max_element(d.begin(), d.end()));
    cout << ans / 2 << '\n';
}
0