結果
問題 | No.390 最長の数列 |
ユーザー | tenten |
提出日時 | 2022-10-14 11:50:31 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 397 ms / 5,000 ms |
コード長 | 1,392 bytes |
コンパイル時間 | 2,291 ms |
コンパイル使用メモリ | 73,896 KB |
実行使用メモリ | 55,824 KB |
最終ジャッジ日時 | 2023-09-08 19:37:04 |
合計ジャッジ時間 | 6,601 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 67 ms
55,824 KB |
testcase_01 | AC | 61 ms
38,592 KB |
testcase_02 | AC | 65 ms
38,884 KB |
testcase_03 | AC | 59 ms
38,512 KB |
testcase_04 | AC | 66 ms
38,888 KB |
testcase_05 | AC | 335 ms
48,376 KB |
testcase_06 | AC | 328 ms
48,232 KB |
testcase_07 | AC | 59 ms
38,848 KB |
testcase_08 | AC | 45 ms
37,688 KB |
testcase_09 | AC | 58 ms
38,328 KB |
testcase_10 | AC | 364 ms
48,668 KB |
testcase_11 | AC | 343 ms
48,152 KB |
testcase_12 | AC | 364 ms
48,020 KB |
testcase_13 | AC | 281 ms
48,284 KB |
testcase_14 | AC | 397 ms
48,040 KB |
testcase_15 | AC | 41 ms
37,476 KB |
testcase_16 | AC | 42 ms
37,612 KB |
testcase_17 | AC | 103 ms
40,340 KB |
testcase_18 | AC | 127 ms
40,892 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); TreeSet<Integer> values = new TreeSet<>(); for (int i = 0; i < n; i++) { values.add(sc.nextInt()); } int[] counts = new int[1000001]; int max = 0; for (int x : values) { max = Math.max(max, counts[x]); for (int j = 2; j * x <= 1000000; j++) { counts[j * x] = Math.max(counts[j * x], counts[x] + 1); } } System.out.println(max + 1); } } 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 String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }