結果

問題 No.930 数列圧縮
ユーザー tentententen
提出日時 2020-10-22 08:17:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 637 ms / 2,000 ms
コード長 1,064 bytes
コンパイル時間 2,829 ms
コンパイル使用メモリ 75,548 KB
実行使用メモリ 63,976 KB
最終ジャッジ日時 2023-09-28 14:33:04
合計ジャッジ時間 15,048 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
55,564 KB
testcase_01 AC 141 ms
55,808 KB
testcase_02 AC 140 ms
55,920 KB
testcase_03 AC 149 ms
55,312 KB
testcase_04 AC 194 ms
56,084 KB
testcase_05 AC 202 ms
58,068 KB
testcase_06 AC 191 ms
56,676 KB
testcase_07 AC 226 ms
58,884 KB
testcase_08 AC 523 ms
63,076 KB
testcase_09 AC 571 ms
62,772 KB
testcase_10 AC 511 ms
62,680 KB
testcase_11 AC 553 ms
62,708 KB
testcase_12 AC 551 ms
62,476 KB
testcase_13 AC 422 ms
60,468 KB
testcase_14 AC 476 ms
60,564 KB
testcase_15 AC 591 ms
62,876 KB
testcase_16 AC 589 ms
62,652 KB
testcase_17 AC 614 ms
63,976 KB
testcase_18 AC 627 ms
62,404 KB
testcase_19 AC 632 ms
62,580 KB
testcase_20 AC 625 ms
62,812 KB
testcase_21 AC 637 ms
62,868 KB
testcase_22 AC 131 ms
55,908 KB
testcase_23 AC 598 ms
62,328 KB
testcase_24 AC 132 ms
55,568 KB
testcase_25 AC 129 ms
55,448 KB
testcase_26 AC 130 ms
55,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        if (arr[0] > arr[n - 1]) {
            System.out.println("No");
            return;
        }
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 1; i < n - 1; i++) {
            if (arr[i] > arr[0]) {
                list.add(arr[i]);
                arr[i] = Integer.MAX_VALUE;
            }
        }
        for (int i = n - 2; i > 0; i--) {
            if (arr[i] < arr[n - 1]) {
                list.add(arr[i]);
            }
        }
        list.add(arr[0]);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < list.size(); i++) {
            if (i > 0) {
                sb.append(" ");
            }
            sb.append(list.get(i));
        }
        System.out.println("Yes");
        System.out.println(sb);
    }
} 
0