結果

問題 No.333 門松列を数え上げ
ユーザー nihi9119nihi9119
提出日時 2017-06-12 16:49:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 1,674 bytes
コンパイル時間 3,158 ms
コンパイル使用メモリ 77,048 KB
実行使用メモリ 53,708 KB
最終ジャッジ日時 2023-10-24 21:36:11
合計ジャッジ時間 4,117 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
53,692 KB
testcase_01 AC 49 ms
53,692 KB
testcase_02 AC 49 ms
53,700 KB
testcase_03 AC 49 ms
51,652 KB
testcase_04 AC 49 ms
53,688 KB
testcase_05 AC 48 ms
53,708 KB
testcase_06 AC 48 ms
53,704 KB
testcase_07 AC 50 ms
53,692 KB
testcase_08 AC 50 ms
53,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package test7;

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

/**
 * No.333 門松列を数え上げ
 * http://yukicoder.me/problems/no/333
 */
public class Question_19_0612_2 {

	final static int MIN = 1;
	final static int MAX = 2 * (int)Math.pow(10, 9);

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

		try {
			//入力
			String[] inputStringList = br.readLine().split(" ");
			int left = Integer.parseInt(inputStringList[0]);
			int center = Integer.parseInt(inputStringList[1]);

			if (NumJudg(left, MIN, MAX) && NumJudg(center, MIN, MAX)) {
				if (left < center) {
					//重複分を除く(left, center)
					System.out.println(center - 2);
				} else {
					System.out.println(MAX - center - 1);
				}
			} 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