結果
問題 |
No.390 最長の数列
|
ユーザー |
![]() |
提出日時 | 2019-11-20 13:00:17 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,365 bytes |
コンパイル時間 | 3,146 ms |
コンパイル使用メモリ | 78,688 KB |
実行使用メモリ | 78,416 KB |
最終ジャッジ日時 | 2024-10-06 02:55:50 |
合計ジャッジ時間 | 9,790 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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); TreeSet<Unit> set = new TreeSet<>(); int max = 1; for (int i = n - 1; i >= 0; i--) { boolean flag = true; for (Unit u : set) { if (u.value % arr[i] == 0) { set.add(new Unit(i, arr[i], u.count + 1)); max = Math.max(max, u.count + 1); flag = false; break; } } if (flag) { set.add(new Unit(i, arr[i], 1)); } } System.out.println(max); } static class Unit implements Comparable<Unit> { int idx; int value; int count; public Unit (int idx, int value, int count) { this.idx = idx; this.value = value; this.count = count; } public int hashCode() { return idx; } public int compareTo(Unit another) { if (count == another.count) { return idx - another.idx; } else { return another.count - count; } } public boolean equals(Object o) { Unit u = (Unit) o; return idx == u.idx && count == u.count; } } }