結果

問題 No.992 最長増加部分列の数え上げ
ユーザー htensaihtensai
提出日時 2020-03-25 13:40:23
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,786 bytes
コンパイル時間 2,548 ms
コンパイル使用メモリ 76,572 KB
実行使用メモリ 134,764 KB
最終ジャッジ日時 2023-08-30 09:33:56
合計ジャッジ時間 12,344 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
134,764 KB
testcase_01 AC 132 ms
55,728 KB
testcase_02 AC 135 ms
53,980 KB
testcase_03 AC 132 ms
55,924 KB
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 -- -
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 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<TreeMap<Integer, Integer>> lists = new ArrayList<>();
        lists.add(new TreeMap<>());
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            for (int j = lists.size() - 1; j >= 0; j--) {
                TreeMap<Integer, Integer> target = lists.get(j);
                Map<Integer, Integer> map = target.headMap(x);
                if (map.size() == 0) {
                    if (j == 0) {
                        if (target.containsKey(x)) {
                            target.put(x, target.get(x) + 1);
                        } else {
                            target.put(x, 1);
                        }
                    }
                } else {
                    int count = 0;
                    for (int y : map.values()) {
                        count += y;
                    }
                    if (j == lists.size() - 1) {
                        TreeMap<Integer, Integer> tmp = new TreeMap<>();
                        tmp.put(x, count);
                        lists.add(tmp);
                    } else {
                        TreeMap<Integer, Integer> tmp = lists.get(j + 1);
                        if (tmp.containsKey(x)) {
                            tmp.put(x, tmp.get(x) + count);
                        } else {
                            tmp.put(x, count);
                        }
                    }
                    break;
                }
            }
        }
        long total = 0;
        for (int x : lists.get(lists.size() - 1).values()) {
            total += x;
        }
        System.out.println(total);
    }
}
0