Submission #51860501


Source Code Expand

/**
 *  @the_hyp0cr1t3
 *  30.03.2024 18:25
**/
#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);

    int n, m;
    std::cin >> n >> m;
    std::vector a(n + 1, std::vector<i64>(n + 1));
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            std::cin >> a[i][j];

    i64 ans = 0;
    for (int z = 0; z < 4; z++) {
        std::vector sum(n + 1, std::vector<i64>(n + 1));
        auto p1 = sum, p2 = sum;

        auto get = [&](int i, int j) {
            return sum[i][j] - sum[i - m][j] - sum[i][j - m] + sum[i - m][j - m];
        };

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                sum[i][j] = a[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
                if (i < m or j < m) continue;
                i64 x = get(i, j);
                p1[i][j] = std::max({x, p1[i - 1][j], p1[i][j - 1]});
                p2[i][j] = std::max({x + p1[i - m][j], x + p1[i][j - m], p2[i - 1][j], p2[i][j - 1]});
            }
        }

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (i < m or j < m) continue;
                ans = std::max(ans, get(i, j) + std::max(p2[n][j - m], p2[i - m][n]));
            }
        }

        for (int i = 1; i <= n; i++)
            std::reverse(a[i].begin() + 1, a[i].end());
        for (int i = 1; i <= n; i++)
            for (int j = i; j <= n; j++)
                std::swap(a[i][j], a[j][i]);
    }

    std::cout << ans << '\n';
}

Submission Info

Submission Time
Task F - Non-overlapping Squares
User the_hyp0cr1t3
Language C++ 20 (gcc 12.2)
Score 525
Code Size 1629 Byte
Status AC
Exec Time 126 ms
Memory 34532 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 3
AC × 34
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_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, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3400 KiB
00_sample_01.txt AC 1 ms 3436 KiB
00_sample_02.txt AC 1 ms 3520 KiB
01_random_03.txt AC 126 ms 34416 KiB
01_random_04.txt AC 126 ms 34420 KiB
01_random_05.txt AC 126 ms 34452 KiB
01_random_06.txt AC 3 ms 3684 KiB
01_random_07.txt AC 1 ms 3536 KiB
01_random_08.txt AC 125 ms 34476 KiB
01_random_09.txt AC 124 ms 34516 KiB
01_random_10.txt AC 123 ms 34388 KiB
01_random_11.txt AC 1 ms 3416 KiB
01_random_12.txt AC 53 ms 16860 KiB
01_random_13.txt AC 115 ms 34440 KiB
01_random_14.txt AC 117 ms 34400 KiB
01_random_15.txt AC 119 ms 34420 KiB
01_random_16.txt AC 106 ms 31560 KiB
01_random_17.txt AC 14 ms 6788 KiB
01_random_18.txt AC 103 ms 34412 KiB
01_random_19.txt AC 105 ms 34508 KiB
01_random_20.txt AC 104 ms 34388 KiB
01_random_21.txt AC 100 ms 33412 KiB
01_random_22.txt AC 61 ms 21560 KiB
01_random_23.txt AC 104 ms 34476 KiB
01_random_24.txt AC 104 ms 34440 KiB
01_random_25.txt AC 104 ms 34532 KiB
01_random_26.txt AC 39 ms 15056 KiB
01_random_27.txt AC 13 ms 6688 KiB
01_random_28.txt AC 88 ms 34516 KiB
01_random_29.txt AC 76 ms 30852 KiB
01_random_30.txt AC 105 ms 34388 KiB
01_random_31.txt AC 16 ms 7656 KiB
01_random_32.txt AC 113 ms 34468 KiB
01_random_33.txt AC 22 ms 9708 KiB