結果
問題 |
No.390 最長の数列
|
ユーザー |
![]() |
提出日時 | 2020-12-14 14:42:58 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 883 bytes |
コンパイル時間 | 2,418 ms |
コンパイル使用メモリ | 79,740 KB |
実行使用メモリ | 63,340 KB |
最終ジャッジ日時 | 2024-09-20 00:43:37 |
合計ジャッジ時間 | 9,827 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 1 TLE * 1 -- * 13 |
ソースコード
import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } Arrays.sort(arr); ArrayList<ArrayList<Integer>> exists = new ArrayList<>(); exists.add(new ArrayList<>()); exists.get(0).add(1); for (int i = 0; i < n; i++) { boolean hit = false; for (int j = exists.size() - 1; j >= 0 && !hit; j--) { for (int x : exists.get(j)) { if (arr[i] % x == 0) { if (j == exists.size() - 1) { exists.add(new ArrayList<>()); } exists.get(j + 1).add(arr[i]); hit = true; break; } } } } System.out.println(exists.size() - 1); } }