Submission #47652900


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>>;
}

constexpr Num MaxHeight = 5000;
constexpr Num MaxWeight = 5000;
Num grid[MaxHeight + 1][MaxWeight + 1];

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

    for(Num i{0}; i<n; ++i) {
        Num h, w;
        is >> h >> w;
        grid[h][w] += 1;
    }

    for(Num h{0}; h<=MaxHeight; ++h) {
        for(Num w{1}; w<=MaxWeight; ++w) {
            grid[h][w] += grid[h][w-1];
        }
    }

    for(Num w{0}; w<=MaxWeight; ++w) {
        for(Num h{1}; h<=MaxHeight; ++h) {
            grid[h][w] += grid[h-1][w];
        }
    }

    Num answer {0};
    for(Num h{k+1}; h<=MaxHeight; ++h) {
        for(Num w{k+1}; w<=MaxWeight; ++w) {
            answer = std::max(answer, grid[w][h] - grid[w-k-1][h] - grid[w][h-k-1] + grid[w-k-1][h-k-1]);
        }
    }

    os << answer << "\n";
}

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

Submission Info

Submission Time
Task 081 - Friendly Group(★5)
User zettsut
Language C++ 20 (gcc 12.2)
Score 5
Code Size 1491 Byte
Status AC
Exec Time 922 ms
Memory 199072 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 5 / 5
Status
AC × 3
AC × 25
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, 09_single_01.txt, 10_small_random_02.txt, 10_small_random_03.txt, 10_small_random_04.txt, 10_small_random_05.txt, 10_small_random_06.txt, 10_small_random_07.txt, 10_small_random_08.txt, 10_small_random_09.txt, 50_large_random_01.txt, 50_large_random_02.txt, 50_large_random_03.txt, 70_all_same_01.txt, 70_chess_board_01.txt, 70_chess_board_02.txt, 70_chess_board_03.txt, 70_distinct_01.txt, 70_distinct_02.txt, 70_sharp_form_01.txt, 70_sharp_form_02.txt, 70_uniform_01.txt, 70_uniform_02.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 563 ms 198824 KiB
00_sample_02.txt AC 612 ms 198884 KiB
00_sample_03.txt AC 564 ms 198980 KiB
09_single_01.txt AC 731 ms 198828 KiB
10_small_random_02.txt AC 582 ms 198884 KiB
10_small_random_03.txt AC 575 ms 199072 KiB
10_small_random_04.txt AC 568 ms 198916 KiB
10_small_random_05.txt AC 583 ms 198860 KiB
10_small_random_06.txt AC 573 ms 198884 KiB
10_small_random_07.txt AC 556 ms 198864 KiB
10_small_random_08.txt AC 592 ms 199032 KiB
10_small_random_09.txt AC 587 ms 199044 KiB
50_large_random_01.txt AC 388 ms 198952 KiB
50_large_random_02.txt AC 922 ms 198880 KiB
50_large_random_03.txt AC 476 ms 198916 KiB
70_all_same_01.txt AC 392 ms 198952 KiB
70_chess_board_01.txt AC 555 ms 198872 KiB
70_chess_board_02.txt AC 558 ms 198876 KiB
70_chess_board_03.txt AC 346 ms 198896 KiB
70_distinct_01.txt AC 655 ms 198920 KiB
70_distinct_02.txt AC 401 ms 198860 KiB
70_sharp_form_01.txt AC 653 ms 198856 KiB
70_sharp_form_02.txt AC 399 ms 198892 KiB
70_uniform_01.txt AC 654 ms 198924 KiB
70_uniform_02.txt AC 396 ms 198876 KiB