RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00624

Zemljište

Unrated 레이팅 미적용
난이도
2s
시간 제한
512MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Matej is, as is well known, the biggest Croatian innovator and businessman. His company
is expanding, which is why he decided to buy a plot of land near Velika Gorica. The
available land is a rectang\(le-sh\)aped region consisting of \(r \times s\) square unit cells. Each
cell has its own price and it’s not possible to purchase only a part of a cell. Matej is
an experienced businessman and he knows that the key to success is not simply to buy
the biggest plot of land or the least expensive one. Instead, he should buy a plot of
land whose price is as close as possible to the magic numbers given to him by Milan the
psychic.
At the beginning of his career, Milan revealed to Matej two magic numbers \(a\) and \(b\) crucial for commercial
success. Therefore, Matej wishes to buy a (nonempty) rectangular plot of land so that the distance
between its price and the magic numbers is as small as possible. The distance between the price and a
single magic number is just the absolute value of their difference, and the distance between the price
and both of the magic numbers is the sum of these absolute differences. Help Matej and determine the
minimum possible distance between the price of the plot of land and the two magic numbers.

제약

Subtask 1 (10 points): \(1 \le r\), \(s \le 20\)

Subtask 2 (20 points): \(1 \le r\), \(s \le 100\)

Subtask 3 (40 points): No additional constraints.

입력 형식

The first line contains positive integers \(r\), \(s\), \(a\) and \(b\) (\(1 \le r\), \(s \le 500\), \(1 \le a\), \(b \le 10^{9}\)) from the problem.
The \(i-th\) of the following \(r\) lines contains a sequence of \(s\) positive integers \(c@@RISE_MATH_BLOCK_0@@ij \le 10^{9}\)), the prices of
the individual cells, in order.

출력 형식

In the only line print the minimum possible distance between the price of the plot of land and the two
magic numbers.

서브태스크
서브태스크점수설명

1

10점

\(1 \le r\), \(s \le 20\)

2

20점

\(1 \le r\), \(s \le 100\)

3

40점

No additional constraints.

예제 1
입력
2 2 10 10
1 3
4 1
출력
2
예제 2
입력
3 2 3 4
1 9
1 1
8 1
출력
3
예제 3
입력
3 4 5 3
1 1 1 1
9 6 7 6
8 1 9 7
출력
2
설명

Clarification of the second example:
Matej can buy a plot of land consisting of two adjacent cells of cost 1. The total price is then 1 + 1 = 2,
and the distance between it and the magic numbers is |3 −2| + |4 −2| = 3.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2021/2022 Contest 6

평가 및 의견

Zemljište

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Zemljište

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8