#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
#include <map>
#include <array>
#include <iomanip>
#include <fstream>
#include <cstdlib>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin>>n>>m;
vector<vector<int> >A(n);
vector<int>a(m,-1);
vector<int>b(m);
vector<vector<int> >val(n);
vector<vector<int> >lo(n);
vector<vector<int> >hi(n);
for(int i=0;i<n;i++){
val[i]=a;
hi[i]=a;
lo[i]=a;
}
for(int i=0;i<n;i++)A[i]=a;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>A[i][j];
hi[i][j]=A[i][j];
lo[i][j]=A[i][j];
}
}
int ans=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(i!=0){
int v=val[i-1][j]-hi[i-1][j]+lo[i-1][j]-1;
int h=max(A[i][j],hi[i-1][j]);
int l=min(A[i][j],lo[i-1][j]);
v+=h;
v-=l;
if(v>val[i][j]){
val[i][j]=v;
hi[i][j]=h;
lo[i][j]=l;
}
}
if(j!=0){
int v=val[i][j-1]-hi[i][j-1]+lo[i][j-1]-1;
int h=max(A[i][j],hi[i][j-1]);
int l=min(A[i][j],lo[i][j-1]);
v+=h;
v-=l;
if(v>val[i][j]){
val[i][j]=v;
hi[i][j]=h;
lo[i][j]=l;
}
}
ans=max(ans,val[i][j]);
}
}
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |