This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define DEBUG(x) cerr << (#x) << ": " << (x) << '\n'
using namespace std;
const int NMAX = 1000;
void Rotate(int &n, int &m, int a[NMAX][NMAX]) {
static int b[NMAX][NMAX];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
b[m - j - 1][i] = a[i][j];
}
}
swap(n, m);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
a[i][j] = b[i][j];
}
}
}
bool uin(int &a, int &b) {
return a > b ? (a = b, true) : false;
}
int Solve(int n, int m, const int a[NMAX][NMAX]) {
int ans = -1;
pair<pair<int, int>, pair<int, int>> per;
static int minim[NMAX][NMAX];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
minim[i][j] = a[i][j] - i - j;
if (i != 0 && uin(minim[i][j], minim[i - 1][j])) {}
if (j != 0 && uin(minim[i][j], minim[i][j - 1])) {}
if (i != 0 && j != 0 && uin(minim[i][j], minim[i - 1][j - 1])) {}
int curr = a[i][j] - i - j - minim[i][j] - 1;
ans = max(ans, curr);
}
}
return ans;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int a[NMAX][NMAX];
int n, m; cin >> n >> m;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> a[i][j];
}
}
int ans = -1;
for (int i = 0; i < 4; ++i) {
ans = max(ans, Solve(n, m, a));
Rotate(n, m, a);
}
cout << ans << endl;
}
# | 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... |