結果

問題 No.365 ジェンガソート
ユーザー nihi9119nihi9119
提出日時 2017-06-20 17:06:24
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,212 bytes
コンパイル時間 3,173 ms
コンパイル使用メモリ 77,380 KB
実行使用メモリ 60,640 KB
最終ジャッジ日時 2024-04-10 05:45:15
合計ジャッジ時間 9,506 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
50,264 KB
testcase_01 AC 50 ms
50,284 KB
testcase_02 AC 52 ms
50,172 KB
testcase_03 AC 53 ms
50,404 KB
testcase_04 AC 51 ms
50,292 KB
testcase_05 AC 49 ms
50,188 KB
testcase_06 AC 51 ms
50,216 KB
testcase_07 AC 51 ms
50,464 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 49 ms
50,284 KB
testcase_15 AC 49 ms
50,320 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 92 ms
51,948 KB
testcase_19 AC 198 ms
60,344 KB
testcase_20 AC 127 ms
54,508 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 203 ms
60,228 KB
testcase_37 AC 201 ms
60,196 KB
testcase_38 WA -
testcase_39 AC 198 ms
59,784 KB
testcase_40 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package test8;

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

/**
 * No.365 ジェンガソート
 * https://yukicoder.me/problems/no/365
 */

public class Question_24_0921 {

	final static int COUNT_MIN = 1;
	final static int LENTTH_MIN = 1;
	final static int COUNT_MAX = 100000;
	static int LENTTH_MAX;

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

		try {
			int count = Integer.parseInt(br.readLine());
			LENTTH_MAX = count;
			String[] inputStr = br.readLine().split(" ");
			//int comparativeNum = Integer.parseInt(inputStr[0]);
			int resultCount = 0;
			int comparativeNum = count;
			boolean errorFlg = false;
			//ArrayList<Integer> list = new ArrayList<Integer>();
			//list.add(Integer.parseInt(inputStr[0]));

			//有効値判定
			if (NumJudg(count, COUNT_MIN, COUNT_MAX)) {
				for (int i = inputStr.length - 1; i > 0; i--) {
					int num = Integer.parseInt(inputStr[i]);
					if (NumJudg(num, LENTTH_MIN, LENTTH_MAX)) {
						if (num == comparativeNum) {
							comparativeNum--;
						} else {
							resultCount++;
						}
					} else {
						errorFlg = true;
						break;
					}
				}
				if (errorFlg) {
					System.out.println("入力値が有効範囲外です");
				} else {
					System.out.println(resultCount);
				}

			} 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