問題一覧 > 通常問題

No.113 Treasure Hunt

レベル : / AI推定難易度 : 115 / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 小数誤差許容問題 絶対誤差または相対誤差が $10^{-2}$ 以下。ただし、ジャッジ側の都合で500桁未満にしてください
タグ : (AC するまで非表示) / 解いたユーザー数 694
作問者 : nmnmnmnmnmnmnm
お気に入りにしたユーザー ProblemId : 278 / 自分の提出
問題文最終更新日: 2026-06-25 06:57:02
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 71 (順位表) の他の問題:

Problem Statement

A-kun has obtained a treasure map.
The map shows a park, with a mark drawn at the center of the park.
It also describes how to move from there.
The movement corresponding to each written character is as follows.

・"N" means move 1 meter north.
・"E" means move 1 meter east.
・"W" means move 1 meter west.
・"S" means move 1 meter south.

For example, if "NE" is written, walk 1 meter north and then walk 1 meter east.
It seems that digging at that point will reveal the treasure.
However, A-kun noticed that these movements are wasteful.
For "NE", it seems sufficient to move just $\sqrt{1^2+1^2}=\sqrt{2}$ meters in the northeast direction.
A-kun wants to move from the center of the park to the location where the treasure is buried by the shortest distance.
Assuming there is no possibility of running into obstacles, how many meters does A-kun need to move?

Input

$S$

The string $S$ written on the map is given in one line.
The length of the string $S$ is at least 1 character and at most 100 characters.
The string consists only of the 4 characters 'N','E','W','S'.

Output

Output the distance from the center of the park to the location where the treasure is buried in one line. An error of up to ±0.01 is allowed.
Do not forget the newline at the end.

Sample

Sample 1
Input
NE
Output
1.41421

This is the same as the example in the problem statement.

Sample 2
Input
EN
Output
1.41421

Walk 1 meter east and then walk 1 meter north.
This ends up at the same location as in Sample 1, so the answer is the same as Sample 1.

Sample 3
Input
SSSSWWW
Output
5

The final position is 4 meters south and 3 meters west.
Therefore, the answer is $\sqrt{4^2+3^2}=5$ meters.

Sample 4
Input
ESSSSEWENWNNEWWEESSS
Output
4.47214

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。