結果
| 問題 |
No.113 宝探し
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-11-22 08:25:39 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 82 ms / 5,000 ms |
| コード長 | 1,655 bytes |
| コンパイル時間 | 9,702 ms |
| コンパイル使用メモリ | 79,208 KB |
| 実行使用メモリ | 43,684 KB |
| 最終ジャッジ日時 | 2025-11-22 08:25:52 |
| 合計ジャッジ時間 | 5,216 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 |
ソースコード
import java.io.*;
class Process {
private String S;
Process(String S) {
this.S = S;
}
double getResult() {
// 各方角の文字の数を格納する配列
// 添え字の小さい順から、北、東、西、南
var directionCount = new int[4];
for(int i = 0; i < S.length(); i++) {
switch(S.charAt(i)) {
case 'N':
directionCount[0]++;
break;
case 'E':
directionCount[1]++;
break;
case 'W':
directionCount[2]++;
break;
case 'S':
directionCount[3]++;
break;
}
}
// 東西方向の移動距離
int horizontalDistance = Math.abs(directionCount[1] - directionCount[2]);
// 南北方向の移動距離
int verticalDistance = Math.abs(directionCount[0] - directionCount[3]);
return Math.sqrt(Math.pow(horizontalDistance, 2) + Math.pow(verticalDistance, 2));
}
}
public class Main {
public static void main(String[] args) throws IOException {
var bufferedReader = new BufferedReader(new InputStreamReader(System.in));
var printWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
// 入力
String S = bufferedReader.readLine().trim();
// 処理および出力
printWriter.println((new Process(S)).getResult());
bufferedReader.close();
printWriter.close();
}
}