結果

問題 No.992 最長増加部分列の数え上げ
ユーザー htensai
提出日時 2020-03-25 13:40:23
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,786 bytes
コンパイル時間 2,373 ms
コンパイル使用メモリ 82,060 KB
実行使用メモリ 156,372 KB
最終ジャッジ日時 2025-01-01 20:31:22
合計ジャッジ時間 110,876 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 1 WA * 11 TLE * 30
権限があれば一括ダウンロードができます

ソースコード

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