結果

問題 No.1188 レベルX門松列
ユーザー tentententen
提出日時 2020-12-29 16:06:06
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,101 bytes
コンパイル時間 3,167 ms
コンパイル使用メモリ 77,664 KB
実行使用メモリ 65,680 KB
最終ジャッジ日時 2024-04-15 16:40:50
合計ジャッジ時間 13,271 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 579 ms
56,176 KB
testcase_01 AC 849 ms
50,852 KB
testcase_02 AC 781 ms
50,756 KB
testcase_03 AC 874 ms
51,448 KB
testcase_04 TLE -
testcase_05 AC 142 ms
41,224 KB
testcase_06 AC 608 ms
49,976 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

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];
        int[] lds = new int[n + 1];
        int maxD = 0;
        lds[0] = Integer.MAX_VALUE;
        int[] lis = new int[n + 1];
        Arrays.fill(lis, Integer.MAX_VALUE);
        lis[0] = 0;
        int maxI = 0;
        int[] leftMaxesI = new int[n];
        int[] leftMaxesD = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            for (int j = maxI; j >= 0; j--) {
                if (lis[j] < arr[i]) {
                    lis[j + 1] = Math.min(lis[j + 1], arr[i]);
                    maxI = Math.max(maxI, j + 1);
                    break;
                }
            }
            leftMaxesI[i] = maxI;
            for (int j = maxD; j >= 0; j--) {
                if (lds[j] > arr[i]) {
                    lds[j + 1] = Math.max(lds[j + 1], arr[i]);
                    maxD = Math.max(maxD, j + 1);
                    break;
                }
            }
            leftMaxesD[i] = maxD;
        }
        Arrays.fill(lds, 0);
        lds[0] = Integer.MAX_VALUE;
        Arrays.fill(lis, Integer.MAX_VALUE);
        lis[0] = 0;
        maxD = 0;
        maxI = 0;
        int ans = 0;
        for (int i = n - 1; i >= 0; i--) {
            for (int j = maxI; j >= 0; j--) {
                if (lis[j] < arr[i]) {
                    lis[j + 1] = Math.min(lis[j + 1], arr[i]);
                    maxI = Math.max(maxI, j + 1);
                    break;
                }
            }
            ans = Math.max(ans, Math.min(leftMaxesI[i], maxI) - 1);
            for (int j = maxD; j >= 0; j--) {
                if (lds[j] > arr[i]) {
                    lds[j + 1] = Math.max(lds[j + 1], arr[i]);
                    maxD = Math.max(maxD, j + 1);
                    break;
                }
            }
            ans = Math.max(ans, Math.min(leftMaxesD[i], maxD) - 1);
        }
        System.out.println(ans);
    }
}
0