結果

問題 No.2436 Min Diff Distance
ユーザー kuronikuroni
提出日時 2023-08-18 22:34:58
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 752 ms / 2,000 ms
コード長 1,737 bytes
コンパイル時間 6,232 ms
コンパイル使用メモリ 258,864 KB
実行使用メモリ 13,732 KB
最終ジャッジ日時 2023-08-18 22:35:15
合計ジャッジ時間 15,058 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 708 ms
13,620 KB
testcase_04 AC 722 ms
13,448 KB
testcase_05 AC 730 ms
13,552 KB
testcase_06 AC 722 ms
13,504 KB
testcase_07 AC 739 ms
13,732 KB
testcase_08 AC 752 ms
13,508 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 285 ms
13,372 KB
testcase_12 AC 315 ms
13,576 KB
testcase_13 AC 443 ms
11,592 KB
testcase_14 AC 52 ms
4,384 KB
testcase_15 AC 706 ms
13,272 KB
testcase_16 AC 252 ms
8,124 KB
testcase_17 AC 619 ms
12,484 KB
testcase_18 AC 514 ms
12,184 KB
testcase_19 AC 605 ms
12,740 KB
testcase_20 AC 371 ms
9,096 KB
testcase_21 AC 136 ms
5,864 KB
testcase_22 AC 54 ms
4,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/segtree>
using namespace std;
using namespace atcoder;

const int INF = 1E9;

int min_op(int u, int v) { return min(u, v); }
int min_e() { return INF; }
int max_op(int u, int v) { return max(u, v); }
int max_e() { return -INF; }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    vector<int> x(n), y(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
    }
    vector<int> mx(n, -INF), mi(n, INF);
    auto solve = [&]() {
        vector<int> p(n), prc(n);
        iota(p.begin(), p.end(), 0);
        iota(prc.begin(), prc.end(), 0);
        sort(p.begin(), p.end(), [&](int u, int v) {
            return pair(x[u], y[u]) < pair(x[v], y[v]);
        });
        vector<int> pos(n);
        for (int i = 0; i < n; i++) {
            pos[p[i]] = i;
        }
        sort(prc.begin(), prc.end(), [&](int u, int v) {
            return pair(y[u], pos[u]) < pair(y[v], pos[v]);
        });
        segtree<int, min_op, min_e> mis(n);
        segtree<int, max_op, max_e> mas(n);
        for (int v : prc) {
            int sum = x[v] + y[v];
            mi[v] = min(mi[v], sum - mas.prod(0, pos[v]));
            mx[v] = max(mx[v], sum - mis.prod(0, pos[v]));
            mas.set(pos[v], sum);
            mis.set(pos[v], sum);
        }
    };
    for (int sx = 0; sx < 2; sx++) {
        for (int sy = 0; sy < 2; sy++) {
            solve();
            transform(y.begin(), y.end(), y.begin(), [](int u) { return -u; });
        }
        transform(x.begin(), x.end(), x.begin(), [](int u) { return -u; });
    }
    int ans = INF;
    for (int i = 0; i < n; i++) {
        ans = min(ans, mx[i] - mi[i]);
    }
    cout << ans;
}
0