Submission #56585353


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/modint>

namespace {
    using ModInt [[maybe_unused]] = atcoder::modint998244353;
    using Num [[maybe_unused]] = long long int;
    using Vec [[maybe_unused]] = std::vector<Num>;
    using Set [[maybe_unused]] = std::set<Num>;
    using Mset [[maybe_unused]] = std::multiset<Num>;
    using Edges [[maybe_unused]] = std::vector<std::vector<Num>>;

    template<typename T>
    using Q [[maybe_unused]] = std::queue<T>;

    template<typename T>
    using PQ [[maybe_unused]] = std::priority_queue<T, std::vector<T>, std::greater<T>>;

    const std::vector<std::pair<Num, Num>> dyxs {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
    std::map<char, std::pair<Num, Num>> directions {{'D', {1, 0}}, {'U', {-1, 0}}, {'R', {0, 1}}, {'L', {0, -1}}};

    template<typename T>
    void print_oneline(const std::vector<T>& vec, std::ostream& os) {
        const auto size = vec.size();
        for(size_t i{0}; i<size; ++i) {
            os << vec.at(i) << (((i+1) == size) ? '\n' : ' ');
        }
    }

    template<typename T>
    void print_each(const std::vector<T>& vec, std::ostream& os) {
        const auto size = vec.size();
        for(size_t i{0}; i<size; ++i) {
            os << vec.at(i) << '\n';
        }
    }
}

Num n, d;
constexpr Num Inf = 1000000000000000LL;

Vec dist(const Vec& xs, Num center) {
    const auto init = center - d;
    Num s {0};
    for(const auto& x : xs) {
        s += std::abs(x - init);
    }

    Vec result(d*2+1);
    result.at(0) = s;
    for(Num i{1}; i<=d*2; ++i) {
        const Num cnt = std::ranges::lower_bound(xs, init + i) - xs.begin();
        s += cnt - (n - cnt);
        result.at(i) = s;
    }

    return result;
}

void solve(std::istream& is, std::ostream& os) {
    is >> n >> d;

    Vec xs(n);
    Vec ys(n);
    Num max_x {Inf};
    Num max_y {Inf};
    for(Num i{0}; i<n; ++i) {
        is >> xs.at(i) >> ys.at(i);
        max_x = std::min(max_x, xs.at(i));
        max_y = std::min(max_y, ys.at(i));
    }
    std::ranges::sort(xs);
    std::ranges::sort(ys);

    auto dxs = dist(xs, max_x);
    std::ranges::sort(dxs);

    auto dys = dist(ys, max_y);
    std::ranges::sort(dys);

    Num ans {0};
    for(const auto& s : dxs) {
        if (d < s) {
            continue;
        }
        const auto w = d - s;
        const Num cnt = std::ranges::upper_bound(dys, w) - dys.begin();
        ans += cnt;
    }

    os << ans << "\n";
}

int main(void) {
    solve(std::cin, std::cout);
    return 0;
}

Submission Info

Submission Time
Task E - Manhattan Multifocal Ellipse
User zettsut
Language C++ 20 (gcc 12.2)
Score 475
Code Size 2600 Byte
Status AC
Exec Time 397 ms
Memory 34316 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 3
AC × 29
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 1 ms 3556 KiB
00_sample_02.txt AC 1 ms 3504 KiB
00_sample_03.txt AC 1 ms 3556 KiB
01_random_01.txt AC 81 ms 9948 KiB
01_random_02.txt AC 36 ms 7048 KiB
01_random_03.txt AC 98 ms 13460 KiB
01_random_04.txt AC 31 ms 6824 KiB
01_random_05.txt AC 47 ms 8324 KiB
01_random_06.txt AC 122 ms 16292 KiB
01_random_07.txt AC 131 ms 19004 KiB
01_random_08.txt AC 158 ms 20044 KiB
01_random_09.txt AC 213 ms 25344 KiB
01_random_10.txt AC 45 ms 8424 KiB
01_random_11.txt AC 59 ms 9956 KiB
01_random_12.txt AC 103 ms 14444 KiB
01_random_13.txt AC 86 ms 12952 KiB
01_random_14.txt AC 27 ms 6336 KiB
01_random_15.txt AC 252 ms 29312 KiB
01_random_16.txt AC 75 ms 11628 KiB
01_random_17.txt AC 16 ms 5200 KiB
01_random_18.txt AC 174 ms 21840 KiB
01_random_19.txt AC 247 ms 28488 KiB
01_random_20.txt AC 278 ms 31600 KiB
02_handmade_01.txt AC 294 ms 32344 KiB
02_handmade_02.txt AC 88 ms 12700 KiB
02_handmade_03.txt AC 397 ms 34240 KiB
02_handmade_04.txt AC 394 ms 34316 KiB
02_handmade_05.txt AC 395 ms 34224 KiB
02_handmade_06.txt AC 397 ms 34224 KiB