#include<bits/stdc++.h>
#include<fstream>
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
//ifstream fin("FEEDING.INP");
//ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ll mxn = 2e5 + 5, base = 972663749;
const ll mod = 911382323, mxv = 1e9 + 1, inf = 2e9;
int n, m;
int col[1005];
int a[1005][1005];
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> a[i][j];
}
}
for(int i = 1; i <= m; i++)col[i] = -inf;
int ans = 0;
for(int i = 1; i <= n; i++){
int mxval = -inf;
for(int j = 1; j <= m; j++){
col[j] = max(col[j], -a[i][j] + i + j);
mxval = max(mxval, col[j]);
ans = max(ans, a[i][j] - i - j + mxval);
}
}
for(int i = 1; i <= m; i++)col[i] = -inf;
for(int i = 1; i <= n; i++){
int mxval = -inf;
for(int j = m; j >= 1; j--){
col[j] = max(col[j], -a[i][j] + i - j);
mxval = max(mxval, col[j]);
ans = max(ans, a[i][j] - i + j + mxval);
}
}
for(int i = 1; i <= m; i++)col[i] = -inf;
for(int i = n; i >= 1; i--){
int mxval = -inf;
for(int j = m; j >= 1; j--){
col[j] = max(col[j], -a[i][j] - i - j);
mxval = max(mxval, col[j]);
ans = max(ans, a[i][j] + i + j + mxval);
}
}
for(int i = 1; i <= m; i++)col[i] = -inf;
for(int i = n; i >= 1; i--){
int mxval = -inf;
for(int j = 1; j <= m; j++){
col[j] = max(col[j], -a[i][j] - i + j);
mxval = max(mxval, col[j]);
ans = max(ans, a[i][j] + i - j + mxval);
}
}
cout << ans - 1;
return(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 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 |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
476 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 |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
476 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
82 ms |
12768 KB |
Output is correct |
19 |
Correct |
78 ms |
12752 KB |
Output is correct |
20 |
Correct |
73 ms |
12368 KB |
Output is correct |
21 |
Correct |
87 ms |
12664 KB |
Output is correct |
22 |
Correct |
90 ms |
12704 KB |
Output is correct |
23 |
Correct |
82 ms |
12732 KB |
Output is correct |
24 |
Correct |
97 ms |
13304 KB |
Output is correct |