結果

問題 No.63 ポッキーゲーム
ユーザー nihi9119nihi9119
提出日時 2017-06-09 08:50:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 47 ms / 5,000 ms
コード長 2,307 bytes
コンパイル時間 3,291 ms
コンパイル使用メモリ 73,664 KB
実行使用メモリ 49,712 KB
最終ジャッジ日時 2023-08-25 19:31:07
合計ジャッジ時間 5,353 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,344 KB
testcase_01 AC 44 ms
49,288 KB
testcase_02 AC 44 ms
49,268 KB
testcase_03 AC 44 ms
49,536 KB
testcase_04 AC 43 ms
49,228 KB
testcase_05 AC 44 ms
49,340 KB
testcase_06 AC 43 ms
49,416 KB
testcase_07 AC 44 ms
47,748 KB
testcase_08 AC 44 ms
49,348 KB
testcase_09 AC 43 ms
49,328 KB
testcase_10 AC 44 ms
49,664 KB
testcase_11 AC 43 ms
49,284 KB
testcase_12 AC 43 ms
49,228 KB
testcase_13 AC 43 ms
49,312 KB
testcase_14 AC 43 ms
49,712 KB
testcase_15 AC 44 ms
49,708 KB
testcase_16 AC 47 ms
49,368 KB
testcase_17 AC 44 ms
49,280 KB
testcase_18 AC 44 ms
49,372 KB
testcase_19 AC 44 ms
49,196 KB
testcase_20 AC 43 ms
49,268 KB
testcase_21 AC 44 ms
49,144 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 center = pokyLneth / 2;
				int touchCount = center / eatLneth;

				//touchCountが0でない、かつ触れる場合はマイナス1する
				if (touchCount != 0 && touchCount * eatLneth * 2 == pokyLneth) {
					touchCount--;
				}

				System.out.println(touchCount * eatLneth);
			}

		} 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