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 はその場に留まるか、まだ終点でなければ経路の次の方向へ 1 歩進めます。Bessie も同様に選べます。初期位置にいる最初の時刻を除き、各時刻の無線の消費エネルギーは二人の距離の二乗です。

FJ と Bessie がそれぞれの終点に初めて両方到着する最後の時刻まで、その時刻も含めて、総消費エネルギーを最小化する共同戦略を計画してください。

入力

1 行目は $N$ と $M$($1 \leq N, M \leq 1000$)、2 行目は整数 $f_x$、$f_y$、3 行目は $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$ の正方向です。

出力

二人の行程で消費する最小エネルギーを表す整数を出力してください。

入出力例

入力 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.