結果

問題 No.415 ぴょん
ユーザー nihi9119nihi9119
提出日時 2017-06-19 18:30:44
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 2,258 bytes
コンパイル時間 3,468 ms
コンパイル使用メモリ 78,636 KB
実行使用メモリ 574,932 KB
最終ジャッジ日時 2024-04-10 06:07:02
合計ジャッジ時間 7,506 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package test8;

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

/**
 * No.415 ぴょん
 * https://yukicoder.me/problems/no/415
 */

public class Question_23_0619 {

	final static int PLACE_MIN = 1; //足場
	final static int INTERVAL_MIN = 1; //1ぴょん幅
	final static int PLACE_MAX = (int)Math.pow(10, 9) * 2;

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

		try {
			String[] inputStrArray = br.readLine().split(" ");
			int place = Integer.parseInt(inputStrArray[0]);
			int interval = Integer.parseInt(inputStrArray[1]);
			int INTERVAL_MAX = place;
			ArrayList<Integer> placeList = new ArrayList<Integer>();

			int nowPlace = 1;
			int stepCount = 0;

			//有効値判定
			if (NumJudg(place, PLACE_MIN, PLACE_MAX) && NumJudg(interval, INTERVAL_MIN, INTERVAL_MAX)) {

				//placeまでの足場を記録 (1は初期値なので除外)
				for (int i = 2; i <= place; i++) {
					placeList.add(i);
				}

				//足場がなくなるまでループ
				while(true) {
					nowPlace += interval;
					if (nowPlace > place) {
						nowPlace = nowPlace - place;
					}
					if (placeList.contains(nowPlace)) {
						placeList.remove(placeList.indexOf(nowPlace));
						stepCount++;
					} else {
						break;
					}
				}

				System.out.println(stepCount);

			} 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