結果

問題 No.1188 レベルX門松列
ユーザー tentententen
提出日時 2020-12-29 16:22:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 788 ms / 2,000 ms
コード長 2,638 bytes
コンパイル時間 2,096 ms
コンパイル使用メモリ 77,556 KB
実行使用メモリ 51,636 KB
最終ジャッジ日時 2024-04-15 16:54:40
合計ジャッジ時間 14,219 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 609 ms
51,176 KB
testcase_01 AC 647 ms
50,816 KB
testcase_02 AC 681 ms
51,012 KB
testcase_03 AC 752 ms
51,636 KB
testcase_04 AC 674 ms
51,440 KB
testcase_05 AC 131 ms
41,260 KB
testcase_06 AC 578 ms
50,716 KB
testcase_07 AC 760 ms
51,560 KB
testcase_08 AC 754 ms
51,268 KB
testcase_09 AC 129 ms
41,328 KB
testcase_10 AC 122 ms
40,204 KB
testcase_11 AC 272 ms
46,236 KB
testcase_12 AC 271 ms
47,276 KB
testcase_13 AC 280 ms
47,568 KB
testcase_14 AC 730 ms
50,400 KB
testcase_15 AC 788 ms
51,188 KB
testcase_16 AC 198 ms
42,900 KB
testcase_17 AC 753 ms
51,124 KB
testcase_18 AC 141 ms
41,612 KB
testcase_19 AC 711 ms
50,636 KB
testcase_20 AC 131 ms
41,116 KB
testcase_21 AC 117 ms
40,008 KB
testcase_22 AC 130 ms
41,324 KB
testcase_23 AC 130 ms
41,364 KB
権限があれば一括ダウンロードができます

ソースコード

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];
        int left;
        int right;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            left = 0;
            right = n;
            while (right - left > 1) {
                int m = (left + right) / 2;
                if (lis[m] < arr[i]) {
                    left = m;
                } else {
                    right = m;
                }
            }
            lis[right] = Math.min(lis[right], arr[i]);
            maxI = Math.max(maxI, right);
            leftMaxesI[i] = maxI;
            left = 0;
            right = n;
            while (right - left > 1) {
                int m = (left + right) / 2;
                if (lds[m] > arr[i]) {
                    left = m;
                } else {
                    right = m;
                }
            }
            lds[right] = Math.max(lds[right], arr[i]);
            maxD = Math.max(maxD, right);
            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--) {
            left = 0;
            right = n;
            while (right - left > 1) {
                int m = (left + right) / 2;
                if (lis[m] < arr[i]) {
                    left = m;
                } else {
                    right = m;
                }
            }
            lis[right] = Math.min(lis[right], arr[i]);
            maxI = Math.max(maxI, right);
            ans = Math.max(ans, Math.min(leftMaxesI[i], maxI) - 1);
            left = 0;
            right = n;
            while (right - left > 1) {
                int m = (left + right) / 2;
                if (lds[m] > arr[i]) {
                    left = m;
                } else {
                    right = m;
                }
            }
            lds[right] = Math.max(lds[right], arr[i]);
            maxD = Math.max(maxD, right);
            ans = Math.max(ans, Math.min(leftMaxesD[i], maxD) - 1);
        }
        System.out.println(ans);
    }
}
0