結果

問題 No.63 ポッキーゲーム
ユーザー nihi9119nihi9119
提出日時 2017-06-08 20:17:16
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,435 bytes
コンパイル時間 3,418 ms
コンパイル使用メモリ 77,696 KB
実行使用メモリ 53,604 KB
最終ジャッジ日時 2023-10-23 19:53:38
合計ジャッジ時間 5,605 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 53 ms
53,584 KB
testcase_04 AC 52 ms
53,596 KB
testcase_05 WA -
testcase_06 AC 52 ms
53,588 KB
testcase_07 AC 52 ms
53,596 KB
testcase_08 WA -
testcase_09 AC 52 ms
53,596 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 52 ms
53,592 KB
testcase_13 AC 52 ms
53,596 KB
testcase_14 AC 52 ms
53,588 KB
testcase_15 AC 53 ms
53,584 KB
testcase_16 AC 53 ms
53,584 KB
testcase_17 AC 52 ms
53,592 KB
testcase_18 AC 53 ms
53,588 KB
testcase_19 AC 52 ms
53,596 KB
testcase_20 AC 52 ms
53,596 KB
testcase_21 AC 53 ms
53,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package test6;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * No.63 ポッキーゲーム http://yukicoder.me/problems/no/63
 * 長さが L(mm)のポッキーを2人はそれぞれ両端から中央に向かって齧っていきます。
 * 2人とも毎回 K(mm) ずつ同じタイミングでポッキーを齧ります。
 * ユウちゃんは恥ずかしがり屋さんなので、
 * 次のタイミングで2人ともポッキーを齧ろうとしたら唇が触れてしまうと分かった時点で齧り進めるのを止めて、
 * 残りは全部ハルカちゃんが食べてしまいます。
 */

public class Question_15_0609_1 {

	static final int POKI_MIN = 1;
	static final int EAT_MIN = 1;
	static final int POKI_MAX = (int)Math.pow(10, 9);
	static final int EAT_MAX = 50;

	public static void main(String[] args) {
		InputStreamReader re = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(re);

		try {
			String[] input = br.readLine().split(" ");
			int pokyLneth = Integer.parseInt(input[0]);
			int eatLneth = Integer.parseInt(input[1]);

			//有効値確認
			if (NumJudg(pokyLneth, POKI_MIN, POKI_MAX)
					&& NumJudg(eatLneth, EAT_MIN, EAT_MAX)) {

				int touchCount = 0;
				int center = pokyLneth / 2;

				//割り切れる場合は、ちょうど触れる数 割り切れない場合は触れる一歩前の数
				if (center % eatLneth == 0) {
					touchCount = center / eatLneth - 1;
				} else {
					touchCount = center / eatLneth;
				}

				System.out.println(touchCount * eatLneth);
			} else {
				System.out.println("入力値が有効範囲外です");
			}

		} catch (NumberFormatException e) {
			System.out.println("数字を入力して下さい。");
		} catch (IOException e) {
			System.out.println("エラーが発生しました。");
		} finally {
			try {
				re.close();
				br.close();
			} catch (IOException e) {
				System.out.println("InputStreamReader、BufferedReaderクローズ中にエラーが発生しました");
			}
		}
	}

	/**
	 * 有効値判定
	 * @param input 判定するもの
	 * @param max 最大値
	 * @param min 最小値
	 * @return 範囲内ならtrue,範囲外ならfalseを返す
	 */
	private static boolean NumJudg(int input, int min, int max) {
		Boolean result = false;
		if (min <= input && input <= max) {
			result = true;
		}
		return result;
	}

}
0