結果

問題 No.992 最長増加部分列の数え上げ
ユーザー tentententen
提出日時 2023-06-08 17:03:34
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,619 bytes
コンパイル時間 3,031 ms
コンパイル使用メモリ 95,176 KB
実行使用メモリ 78,356 KB
最終ジャッジ日時 2023-08-29 22:36:38
合計ジャッジ時間 27,441 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
56,376 KB
testcase_01 AC 45 ms
49,528 KB
testcase_02 AC 45 ms
49,604 KB
testcase_03 AC 45 ms
49,548 KB
testcase_04 AC 464 ms
64,304 KB
testcase_05 AC 389 ms
64,016 KB
testcase_06 AC 486 ms
66,512 KB
testcase_07 AC 459 ms
66,492 KB
testcase_08 AC 302 ms
59,516 KB
testcase_09 AC 461 ms
66,492 KB
testcase_10 AC 493 ms
66,468 KB
testcase_11 AC 567 ms
68,948 KB
testcase_12 AC 254 ms
58,032 KB
testcase_13 AC 395 ms
66,380 KB
testcase_14 AC 426 ms
64,176 KB
testcase_15 AC 259 ms
56,880 KB
testcase_16 AC 772 ms
75,364 KB
testcase_17 AC 291 ms
61,540 KB
testcase_18 AC 416 ms
64,636 KB
testcase_19 AC 618 ms
70,796 KB
testcase_20 AC 778 ms
76,620 KB
testcase_21 AC 826 ms
75,964 KB
testcase_22 AC 864 ms
76,032 KB
testcase_23 AC 858 ms
75,344 KB
testcase_24 AC 831 ms
78,356 KB
testcase_25 AC 821 ms
75,884 KB
testcase_26 AC 861 ms
75,960 KB
testcase_27 AC 843 ms
75,456 KB
testcase_28 AC 794 ms
76,144 KB
testcase_29 AC 747 ms
74,932 KB
testcase_30 TLE -
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.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        ArrayList<TreeMap<Integer, Integer>> lis = new ArrayList<>();
        lis.add(new TreeMap<>());
        lis.get(0).put(Integer.MIN_VALUE, 1);
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            int left = 0;
            int right = lis.size();
            while (right - left > 1) {
                int m = (left + right) / 2;
                if (lis.get(m).firstKey() < x) {
                    left = m;
                } else {
                    right = m;
                }
            }
            if (right >= lis.size()) {
                lis.add(new TreeMap<>());
            }
            int count = 0;
            for (int y : lis.get(left).keySet()) {
                if (x <= y) {
                    break;
                }
                count += lis.get(left).get(y);
                count %= MOD;
            }
            lis.get(right).put(x, (lis.get(right).getOrDefault(x, 0) + count) % MOD);
        }
        int ans = 0;
        for (int v : lis.get(lis.size() - 1).values()) {
            ans += v;
            ans %= MOD;
        }
        System.out.println(ans);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0