QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#21170. 柵の中

Statistics

Farmer John は多くの牛が奇妙にも広場恐怖症(広い開放空間を恐れる)だと気づきました。放牧の恐怖を減らすため、縦(南北)と横(東西)の柵で大きな畑を小さな領域に分けます。

畑は角 $(0,0)$ と $(A,B)$ の長方形です。異なる位置 $a_1 \ldots a_n$ ($0 < a_i < A$) に $n$ 本の縦柵 ($0 \leq n \leq 2000$) を $(a_i, 0)$ から $(a_i, B)$ まで作ります。位置 $b_1 \ldots b_m$ ($0 < b_i < B$) には $m$ 本の横柵 ($0 \leq m \leq 2000$) を $(0, b_i)$ から $(A, b_i)$ まで作ります。各縦柵は各横柵と交わり、計 $(n+1)(m+1)$ 領域になります。

門を忘れたため牛は領域から出て畑全体を歩けません!隣接領域間の柵を取り除いて直します。いくつかの隣接領域の組を選び、その間の柵を全長除去し、牛が開口を通って畑のどこへでも行けるようにします。

例えば次の柵を:

+---+--+
|   |  |
+---+--+
|   |  |  
|   |  |
+---+--+

こう開けられます:

+---+--+
|      |  
+---+  +  
|      |  
|      |
+---+--+

目的を達成する除去柵の最小総長を求めてください。

入力

最初の行は $A$、$B$、$n$、$m$ ($1 \leq A, B \leq 1,000,000,000$)。続く $n$ 行は $a_1 \ldots a_n$、その後 $m$ 行は $b_1 \ldots b_m$。

出力

除去する最小長を出力します。標準 32 ビット整数に収まらない可能性があり、64 ビット型(C/C++ の long long など)が必要かもしれません。

入出力例

入力 1

15 15 5 2
2
5
10
6
4
11
3

出力 1

44

問題作成:Brian Dean

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.