結果

問題 No.930 数列圧縮
ユーザー htensai
提出日時 2020-05-15 09:19:25
言語 Java
(openjdk 23)
結果
AC  
実行時間 664 ms / 2,000 ms
コード長 925 bytes
コンパイル時間 2,765 ms
コンパイル使用メモリ 74,996 KB
実行使用メモリ 59,876 KB
最終ジャッジ日時 2024-09-17 15:32:02
合計ジャッジ時間 16,303 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        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();
        }
        StringBuilder sb = new StringBuilder();
        if (arr[0] < arr[n - 1]) {
            sb.append("Yes\n");
            for (int i = 1; i < n - 1; i++) {
                if (arr[0] < arr[i]) {
                    sb.append(arr[i]).append(" ");
                    arr[i] = Integer.MAX_VALUE;
                }
            }
            for (int i = n - 2; i >= 1; i--) {
                 if (arr[i] < arr[n - 1]) {
                    sb.append(arr[i]).append(" ");
                }
            }
            sb.append(arr[0]);
        } else {
            sb.append("No");
        }
        System.out.println(sb);
    }
}
0