답안 #189132

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
189132 2020-01-13T21:08:59 Z Nicksechko Maxcomp (info1cup18_maxcomp) C++14
100 / 100
190 ms 21128 KB
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

const int inf = 1'000'000'088;

template<typename T>
T& InplaceMin(T& a, const T& b) {
    return a = min(a, b);
}

template<typename T>
T& InplaceMax(T& a, const T& b) {
    return a = max(a, b);
}

int Calc(const vector<vector<int>>& a) {
    int result = -inf;

    vector<int> mins(a[0].size(), inf);
    for (const auto& row : a) {
        int pref_min = inf;
        for (int j = 0; j < row.size(); ++j) {
            mins[j] = min(mins[j], pref_min) + 1;
            pref_min = InplaceMin(mins[j], row[j] + 1);
            InplaceMax(result, row[j] - mins[j]);
        }
    }

    return result;
}

void Rotate(vector<vector<int>>& a) {
    int n = a.size(), m = a[0].size();

    vector<vector<int>> new_a(m, vector<int>(n));
    for (int i = 0; i < a.size(); ++i) {
        for (int j = 0; j < a[i].size(); ++j) {
            new_a[j][n - i - 1] = a[i][j];
        }
    }

    a = new_a;
}

void Solve(istream& in, ostream& out) {
    int n = 0, m;
    in >> n >> m;

    vector<vector<int>> a(n, vector<int>(m));
    for (auto& row : a) {
        for (int& item : row) {
            in >> item;
        }
    }

    int ans = -1;
    for (int i = 0; i < 4; i++) {
        Rotate(a);
        InplaceMax(ans, Calc(a));
    }

    out << ans << endl;
}

int main() {
    std::ios_base::sync_with_stdio(false);

    Solve(cin, cout);

    return 0;
}

Compilation message

maxcomp.cpp: In function 'int Calc(const std::vector<std::vector<int> >&)':
maxcomp.cpp:25:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < row.size(); ++j) {
                         ~~^~~~~~~~~~~~
maxcomp.cpp: In function 'void Rotate(std::vector<std::vector<int> >&)':
maxcomp.cpp:39:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a.size(); ++i) {
                     ~~^~~~~~~~~~
maxcomp.cpp:40:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < a[i].size(); ++j) {
                         ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 248 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 0 ms 376 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 248 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 248 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 0 ms 376 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 189 ms 16820 KB Output is correct
19 Correct 190 ms 16696 KB Output is correct
20 Correct 168 ms 16228 KB Output is correct
21 Correct 188 ms 16736 KB Output is correct
22 Correct 187 ms 16736 KB Output is correct
23 Correct 178 ms 16900 KB Output is correct
24 Correct 182 ms 21128 KB Output is correct