이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct cell
{
int x, i, j;
};
bool operator < (const cell a, const cell b)
{
return a.x <= b.x;
}
cell a[1000001];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
int N = 0;
for (int i=0; i<n; i++)
{
for (int j=0; j<m; j++)
{
int x;
cin >> x;
a[++N].x = x;
a[N].i = i, a[N].j = j;
}
}
sort (a+1, a+N+1);
int M = N/2 + 1;
int ans = -1;
for (int i=1; i<M; i++)
{
for (int j=N; j>=M; 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;
if (s <= ans)
break;
ans = max(ans, s - d);
}
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |