QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#442249#8519. Radarsucup-team2010#WA 1ms3816kbC++202.0kb2024-06-15 10:36:212024-06-15 10:36:21

Judging History

你现在查看的是最新测评结果

  • [2024-06-15 10:36:21]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3816kb
  • [2024-06-15 10:36:21]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

bool check(const std::vector<std::vector<bool>>& g) {
    for (const auto& row : g) {
        for (bool covered : row) {
            if (!covered) {
                return false;
            }
        }
    }
    return true;
}

std::tuple<i64, std::vector<std::pair<int, int>>> cal(int n, const std::vector<std::vector<int>>& a) {
    using T = std::tuple<i64, int, int>;
    std::priority_queue<T, std::vector<T>, std::greater<T>> pq;

    std::vector<std::vector<bool>> g(n, std::vector<bool>(n, false));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            pq.push({a[i][j], i, j});
        }
    }

    i64 tot = 0;
    std::vector<std::pair<int, int>> r;

    int rr = (n - 1) / 2;

    std::vector<std::pair<int, int>> d;
    for (int dx = -rr; dx <= rr; ++dx) {
        for (int dy = -rr; dy <= rr; ++dy) {
            d.emplace_back(dx, dy);
        }
    }

    while (!check(g)) {
        auto [cost, x, y] = pq.top();
        pq.pop();

        tot += cost;
        r.emplace_back(x, y);

        for (const auto& [dx, dy] : d) {
            int nx = x + dx;
            int ny = y + dy;
            if (0 <= nx && nx < n && 0 <= ny && ny < n) {
                g[nx][ny] = true;
            }
        }
    }

    return {tot, r};
}

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

    int t;
    std::cin >> t;

    std::vector<std::tuple<int, std::vector<std::vector<int>>>> test;

    for (int i = 0; i < t; i++) {
        int n;
        std::cin >> n;

        std::vector<std::vector<int>> a(n, std::vector<int>(n));
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                std::cin >> a[i][j];
            }
        }
        test.emplace_back(n, a);
    }

    for (const auto& [n, a] : test) {
        auto [tot, r] = cal(n, a);
        tot = std::min((i64)a[n / 2][n / 2], tot);
        std::cout << tot << "\n";
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3668kb

input:

2
3
1 1 1
1 1 1
1 1 1
5
8 5 2 8 3
5 6 9 7 3
7 8 9 1 4
8 9 4 5 5
2 8 6 9 3

output:

1
5

result:

ok 2 number(s): "1 5"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

1
1
444739567

output:

444739567

result:

ok 1 number(s): "444739567"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3816kb

input:

32
5
177252602 814271963 432801178 401470194 888319541
320323627 34071000 116035631 87392694 926990496
423510770 515133425 777623990 140441392 853473387
976288681 925949889 930584554 939702106 761328886
840677679 912446055 378955738 997133668 334407172
3
633852912 89450314 828384045
327867173 732812...

output:

777623990
732812691
47298040
380895866
67457874
954430705
308216403
651528402
199272913
309454602
333898451
363684390
40604467
266308644
506622525
60323753
288280297
114032585
461004500
740248859
49710371
75128942
269414925
755829169
168849689
108744675
691515792
315594750
469380143
226211000
227141...

result:

wrong answer 1st numbers differ - expected: '494991369', found: '777623990'