이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9+1e7;
const int mx = 1005;
void ckmax(int& a, int b){
a = max(a, b);
}
int N, M;
int A[mx][mx];
int nA[mx][mx];
void rot(){
for(int i = 1; i <= N; i++){
for(int j = 1; j <= M; j++){
nA[M+1-j][i] = A[i][j];
}
}
swap(N, M);
for(int i = 1; i <= N; i++){
for(int j = 1; j <= M; j++){
A[i][j] = nA[i][j];
}
}
}
int maxSub[mx][mx];
int getAns(){
for(int i = 0; i <= N; i++){
for(int j = 0; j <= M; j++){
maxSub[i][j] = -INF;
}
}
for(int i = 1; i <= N; i++){
for(int j = 1; j <= M; j++){
maxSub[i][j] = -A[i][j]+i+j;
}
}
int ans = -INF;
for(int i = 1; i <= N; i++){
for(int j = 1; j <= M; j++){
ckmax(maxSub[i][j], max(maxSub[i-1][j], max(maxSub[i][j-1], maxSub[i-1][j-1])));
//cout << maxSub[i][j] << " ";
ckmax(ans, A[i][j]-i-j+maxSub[i][j]-1);
}
//cout << "\n";
}
return ans;
}
int main(){
cin >> N >> M;
for(int i = 1; i <= N; i++){
for(int j = 1; j <= M; j++){
cin >> A[i][j];
}
}
int ans = -INF;
for(int i = 0; i < 4; i++){
ckmax(ans, getAns());
rot();
}
cout << ans << "\n";
}
# | 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... |