이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
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) {
~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |