QOJ.ac

QOJ

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

#21157. 無線電聯繫

Statistics

Farmer John 丟了最喜歡的牛鈴,Bessie 答應幫他尋找!他們分頭沿不同路線搜尋農場,用無線電保持聯繫。不幸的是,無線電電池快沒電了,因此他們想規劃行動,盡量一直保持較近的距離以節約電量。

Farmer John 從 $(f_x, f_y)$ 出發,計畫走一條有 $N$ 步的路線,每步為 'N'(北)、'E'(東)、'S'(南)或 'W'(西)。Bessie 從 $(b_x, b_y)$ 出發,走類似的 $M$ 步路線。兩條路線可以有共用點。每個時間步,Farmer John 可留在原地,或沿路線的下一個方向前進一步(若尚未到達路線終點)。Bessie 同樣可以選擇。每個時間步(不計他們位於初始位置的第一步),無線電消耗的能量等於兩者距離的平方。

請幫助 FJ 與 Bessie 規劃聯合行動策略,使總耗能最小,計入直到兩者首次都到達各自終點的最後一步。

輸入格式

輸入第一行包含 $N$ 和 $M$($1 \leq N, M \leq 1000$)。第二行包含整數 $f_x$、$f_y$,第三行包含 $b_x$、$b_y$($0 \leq f_x, f_y, b_x, b_y \leq 1000$)。下一行是描述 FJ 路線的長度為 $N$ 的字串,最後一行是描述 Bessie 路線的長度為 $M$ 的字串。

保證他們全程座標都在 $0 \leq x,y \leq 1000$ 內。注意東是 $x$ 正方向,北是 $y$ 正方向。

輸出格式

輸出一個整數,表示 FJ 與 Bessie 行程中的最小耗能。

範例

輸入格式 1

2 7
3 0
5 0
NN
NWWWWWN

輸出格式 1

28

題目作者: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.