結果
問題 |
No.365 ジェンガソート
|
ユーザー |
![]() |
提出日時 | 2018-06-04 16:21:39 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 656 ms / 2,000 ms |
コード長 | 1,415 bytes |
コンパイル時間 | 3,716 ms |
コンパイル使用メモリ | 80,004 KB |
実行使用メモリ | 62,080 KB |
最終ジャッジ日時 | 2024-06-30 09:42:38 |
合計ジャッジ時間 | 20,985 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 41 |
ソースコード
import java.util.Scanner; import java.util.ArrayList; import java.util.InputMismatchException; public class JengaSort { static Scanner scanner = new Scanner(System.in); public static void main(String[] args){ int N = Input(1 , 100000); ArrayList<Integer> High = new ArrayList<>(); for(int i = 0 ; i < N ; i++){ High.add(Input(1,N)); } int Result = Processing(N,High); System.out.println(N - Result); } public static int Input(int Min , int Max){ int Number = scanner.nextInt(); try{ if(Number < Min || Number > Max){ System.out.println(Min + "以上" + Max + "以下で入力してください"); System.exit(0); } }catch(InputMismatchException e){ System.out.println("数字を入力してください"); System.exit(0); }catch(Exception E){ System.out.println("予期せぬエラーです"); System.exit(0); } return Number; } public static int Processing(int N , ArrayList<Integer> High){ int Count = 0; int Match = N; for(int i = N - 1 ; i >= 0 ; i--){ if(High.get(i) == Match){ Count++; Match--; } } //System.out.println(Count); return Count; } }