이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MAXN = 1000;
ll mat1[MAXN+5][MAXN+5];
ll mat2[MAXN+5][MAXN+5];
ll mat3[MAXN+5][MAXN+5];
ll mat4[MAXN+5][MAXN+5];
ll a[MAXN+5][MAXN+5];
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n, m;
cin >> n >> m;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cin >> a[i][j];
}
}
ll res = -1;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
mat1[i][j] = i+j - a[i][j];
if(i > 1) mat1[i][j] = max(mat1[i][j], mat1[i-1][j]);
if(j > 1) mat1[i][j] = max(mat1[i][j], mat1[i][j-1]);
}
}
for(int i=1; i<=n; i++){
for(int j=m; j>=1; j--){
mat2[i][j] = i-j - a[i][j];
if(i > 1) mat2[i][j] = max(mat2[i][j], mat2[i-1][j]);
if(j < m) mat2[i][j] = max(mat2[i][j], mat2[i][j+1]);
}
}
for(int i=n; i>=1; i--){
for(int j=1; j<=m; j++){
mat3[i][j] = -i+j - a[i][j];
if(i < n) mat3[i][j] = max(mat3[i][j], mat3[i+1][j]);
if(j > 1) mat3[i][j] = max(mat3[i][j], mat3[i][j-1]);
}
}
for(int i=n; i>=1; i--){
for(int j=m; j>=1; j--){
mat4[i][j] = -i-j - a[i][j];
if(i < n) mat4[i][j] = max(mat4[i][j], mat4[i+1][j]);
if(j < m) mat4[i][j] = max(mat4[i][j], mat4[i][j+1]);
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
res = max(res, a[i][j]-i-j + mat1[i][j] - 1);
res = max(res, a[i][j]-i+j + mat2[i][j] - 1);
res = max(res, a[i][j]+i-j + mat3[i][j] - 1);
res = max(res, a[i][j]+i+j + mat4[i][j] - 1);
}
}
cout << res << "\n";
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... |