이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tpl;
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
int a[1010][1010], colPos[1010], colNeg[1010], n, m;
int solve() {
int ans = 0;
for (int j = 1; j <= m; j++) colPos[j] = colNeg[j] = INT_MIN;
for (int i = 1; i <= n; i++) {
int bestPos = INT_MIN, bestNeg = INT_MIN;
for (int j = 1; j <= m; j++) {
colPos[j] = max(colPos[j], a[i][j] + i + j);
colNeg[j] = max(colNeg[j], -a[i][j] + i + j);
bestPos = max(bestPos, colPos[j]);
bestNeg = max(bestNeg, colNeg[j]);
ans = max({ans, a[i][j] - i - j + bestNeg, bestPos - a[i][j] - i - j});
}
}
return ans;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) cin >> a[i][j];
int save = solve();
for (int i = 1; i <= n; i++) reverse(a[i] + 1, a[i] + 1 + m);
cout << max(save, solve()) - 1;
return 0;
}
# | 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... |