結果

問題 No.365 ジェンガソート
ユーザー SagTokiSagToki
提出日時 2018-06-04 15:17:43
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,591 bytes
コンパイル時間 5,151 ms
コンパイル使用メモリ 79,256 KB
実行使用メモリ 65,244 KB
最終ジャッジ日時 2023-09-12 22:10:33
合計ジャッジ時間 19,171 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,876 KB
testcase_01 AC 122 ms
55,496 KB
testcase_02 AC 124 ms
55,696 KB
testcase_03 AC 124 ms
55,660 KB
testcase_04 AC 124 ms
55,724 KB
testcase_05 AC 124 ms
55,832 KB
testcase_06 AC 124 ms
55,420 KB
testcase_07 AC 124 ms
55,500 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 125 ms
55,724 KB
testcase_11 WA -
testcase_12 AC 125 ms
55,468 KB
testcase_13 WA -
testcase_14 AC 125 ms
55,884 KB
testcase_15 AC 134 ms
55,776 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 245 ms
59,636 KB
testcase_19 AC 579 ms
63,740 KB
testcase_20 AC 392 ms
60,380 KB
testcase_21 AC 337 ms
60,892 KB
testcase_22 AC 497 ms
62,648 KB
testcase_23 AC 409 ms
60,620 KB
testcase_24 AC 472 ms
58,736 KB
testcase_25 AC 315 ms
60,704 KB
testcase_26 WA -
testcase_27 AC 565 ms
62,748 KB
testcase_28 AC 472 ms
60,660 KB
testcase_29 AC 549 ms
63,012 KB
testcase_30 AC 480 ms
60,480 KB
testcase_31 AC 332 ms
60,768 KB
testcase_32 AC 322 ms
60,588 KB
testcase_33 AC 541 ms
62,744 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 540 ms
65,244 KB
testcase_37 AC 544 ms
62,676 KB
testcase_38 WA -
testcase_39 AC 574 ms
65,092 KB
testcase_40 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
        if(Result == 1){
            System.out.println(N - Result);
        }else{
            System.out.println(N - Result - 1);
        }
    }
    
    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 = 1;
        for(int i = N - 1 ; i > 0 ; i--){
            if(High.get(i) == N){
                for(int j = i - 1 ; j > 0 ; j--){
                    if(High.get(j) == N - 1){
                        Count++;
                        N--;
                    }
                }
            }
        }
        return Count;
    }
}
0