結果
問題 | No.992 最長増加部分列の数え上げ |
ユーザー |
![]() |
提出日時 | 2020-08-24 19:38:47 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,691 bytes |
コンパイル時間 | 2,348 ms |
コンパイル使用メモリ | 80,064 KB |
実行使用メモリ | 90,964 KB |
最終ジャッジ日時 | 2024-11-06 10:37:32 |
合計ジャッジ時間 | 22,130 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 TLE * 1 -- * 14 |
ソースコード
import java.util.*;import java.io.*;public class Main {static final int MOD = 1000000007;public static void main(String[] args) throws Exception {BufferedReader br = new BufferedReader(new InputStreamReader(System.in));int n = Integer.parseInt(br.readLine());ArrayList<TreeMap<Integer, Integer>> list = new ArrayList<>();list.add(new TreeMap<>());list.get(0).put(Integer.MIN_VALUE, 1);String[] line = br.readLine().split(" ", n);for (int i = 0; i < n; i++) {int x = Integer.parseInt(line[i]);int left = 0;int right = list.size();while (right - left > 1) {int m = (left + right) / 2;if (list.get(m).firstKey() >= x) {right = m;} else {left = m;}}if (left == list.size() - 1) {list.add(new TreeMap<>());}int count = 0;for (Map.Entry<Integer, Integer> entry : list.get(left).entrySet()) {if (entry.getKey() >= x) {break;}count += entry.getValue();count %= MOD;}if (list.get(left + 1).containsKey(x)) {list.get(left + 1).put(x, (list.get(left + 1).get(x) + count) % MOD);} else {list.get(left + 1).put(x, count);}}int sum = 0;for (int x : list.get(list.size() - 1).values()) {sum += x;sum %= MOD;}System.out.println(sum);}}