#include <bits/stdc++.h>
#define ll long long
#define INF 10000000000
using namespace std;
int n, m;
ll ans = -INF;
vector<vector<ll>> v;
void f(){
vector<vector<ll>> mi(n + 1, vector<ll>(m + 1, INF));
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
mi[i][j] = min(mi[i][j - 1] + 1, v[i][j]);
}
}
vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, INF));
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
dp[i][j] = min(dp[i - 1][j] + 1, mi[i][j]);
ans = max(ans, abs(v[i][j] - dp[i][j]) - 1);
}
}
}
void swv(){
for(int i = 1; i <= n / 2; i++){
swap(v[i], v[n - i + 1]);
}
}
void swh(){
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m / 2; j++){
swap(v[i][j], v[i][m - j + 1]);
}
}
}
int main(){
cin>>n>>m;
v.assign(n + 1, vector<ll>(m + 1, 0));
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
cin>>v[i][j];
}
}
f();
swh();
f();
swv();
f();
swh();
f();
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
440 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
440 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
500 KB |
Output is correct |
13 |
Correct |
2 ms |
508 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
440 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
512 KB |
Output is correct |
13 |
Correct |
2 ms |
592 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
500 KB |
Output is correct |
16 |
Correct |
2 ms |
508 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
283 ms |
32552 KB |
Output is correct |
19 |
Correct |
268 ms |
32656 KB |
Output is correct |
20 |
Correct |
256 ms |
31128 KB |
Output is correct |
21 |
Correct |
290 ms |
32608 KB |
Output is correct |
22 |
Correct |
286 ms |
32632 KB |
Output is correct |
23 |
Correct |
298 ms |
32644 KB |
Output is correct |
24 |
Correct |
298 ms |
32200 KB |
Output is correct |