#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e3+100;
const ll INF = 1e18;
const int di[] = {-1, -1, 1, 1};
const int dj[] = {-1, 1, 1, -1};
ll a[N][N], p[4][N][N], n, m;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m;
for (int i=1; i<=n; ++i) {
for (int j=1; j<=m; ++j) cin>>a[i][j];
}
for (int k=0; k<4; ++k) {
for (int i=0; i<=n+1; ++i) {
for (int j=0; j<=m+1; ++j) p[k][i][j]=INF;
}
}
// 0
for (ll i=1; i<=n; ++i) {
for (ll j=1; j<=m; ++j) {
p[0][i][j]=min({p[0][i-1][j], p[0][i][j-1], a[i][j]+i*di[0]+j*dj[0]});
}
}
// 1
for (ll i=1; i<=n; ++i) {
for (ll j=m; j>=1; --j) {
p[1][i][j]=min({p[1][i-1][j], p[1][i][j+1], a[i][j]+i*di[1]+j*dj[1]});
}
}
// 2
for (ll i=n; i>=1; --i) {
for (ll j=m; j>=1; --j) {
p[2][i][j]=min({p[2][i+1][j], p[2][i][j+1], a[i][j]+i*di[2]+j*di[2]});
}
}
// 3
for (ll i=n; i>=1; --i) {
for (ll j=1; j<=m; ++j) {
p[3][i][j]=min({p[3][i+1][j], p[3][i][j-1], a[i][j]+i*di[3]+j*dj[3]});
}
}
ll ans=-1;
for (ll i=1; i<=n; ++i) {
for (ll j=1; j<=m; ++j) {
for (int k=0; k<4; ++k) {
ans=max(ans, a[i][j]+di[k]*i+dj[k]*j-p[k][i][j]-1);
}
}
}
cout<<ans<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
1364 KB |
Output is correct |
10 |
Correct |
1 ms |
1364 KB |
Output is correct |
11 |
Correct |
1 ms |
1364 KB |
Output is correct |
12 |
Correct |
1 ms |
1364 KB |
Output is correct |
13 |
Correct |
1 ms |
1364 KB |
Output is correct |
14 |
Correct |
1 ms |
1364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
1364 KB |
Output is correct |
13 |
Correct |
1 ms |
1364 KB |
Output is correct |
14 |
Correct |
1 ms |
1364 KB |
Output is correct |
15 |
Correct |
1 ms |
1364 KB |
Output is correct |
16 |
Correct |
1 ms |
1364 KB |
Output is correct |
17 |
Correct |
1 ms |
1364 KB |
Output is correct |
18 |
Correct |
126 ms |
43356 KB |
Output is correct |
19 |
Correct |
129 ms |
43448 KB |
Output is correct |
20 |
Correct |
119 ms |
43340 KB |
Output is correct |
21 |
Correct |
125 ms |
43448 KB |
Output is correct |
22 |
Correct |
144 ms |
43396 KB |
Output is correct |
23 |
Correct |
138 ms |
43352 KB |
Output is correct |
24 |
Correct |
121 ms |
41236 KB |
Output is correct |