#include <bits/stdc++.h>
using namespace std;
struct cell
{
int x;
int i, j;
};
bool comp (cell a, cell b)
{
if (a.x == b.x)
{
if (a.i == b.i)
return a.j < b.j;
return a.i < b.i;
}
return a.x < b.x;
}
cell a[1000001];
int main()
{
int n, m;
cin >> n >> m;
int N = 0;
for (int i=1; i<=n; i++)
{
for (int j=1; j<=m; j++)
{
int x;
cin >> x;
N++;
a[N].x = x;
a[N].i = i, a[N].j = j;
}
}
sort (a+1, a+N+1, comp);
int ans = -1;
for (int i=1; i<N; i++)
{
for (int j=N; j>i; j--)
{
int d = abs(a[i].i - a[j].i) + abs(a[i].j - a[j].j) + 1;
int s = a[j].x - a[i].x - d;
ans = max(ans, s);
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
7 ms |
340 KB |
Output is correct |
10 |
Correct |
8 ms |
212 KB |
Output is correct |
11 |
Correct |
7 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
332 KB |
Output is correct |
13 |
Correct |
7 ms |
340 KB |
Output is correct |
14 |
Correct |
7 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
316 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
340 KB |
Output is correct |
13 |
Correct |
8 ms |
212 KB |
Output is correct |
14 |
Correct |
7 ms |
340 KB |
Output is correct |
15 |
Correct |
8 ms |
332 KB |
Output is correct |
16 |
Correct |
7 ms |
340 KB |
Output is correct |
17 |
Correct |
7 ms |
340 KB |
Output is correct |
18 |
Execution timed out |
1092 ms |
11944 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |