結果
問題 |
No.979 Longest Divisor Sequence
|
ユーザー |
|
提出日時 | 2020-02-01 00:50:55 |
言語 | Java (openjdk 23) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,276 bytes |
コンパイル時間 | 2,983 ms |
コンパイル使用メモリ | 79,380 KB |
実行使用メモリ | 91,084 KB |
最終ジャッジ日時 | 2024-09-17 13:45:52 |
合計ジャッジ時間 | 10,630 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 TLE * 1 |
ソースコード
// This file is a "Hello, world!" in Java language by OpenJDK for wandbox. import java.util.*; import java.io.*; class Main { public static void main(String[] args) { new Main().run(); } void run(){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int[] A=new int[N]; ArrayList<Integer>[] a=new ArrayList[(int)3e5+1]; for(int i=0;i<a.length;++i)a[i]=new ArrayList<>(); for(int i=0;i<N;++i){ A[i]=sc.nextInt(); a[A[i]].add(i); } for(int i=0;i<a.length;++i)Collections.sort(a[i]); int[] dp=new int[(int)3e5+1]; for(int i=0;i<N;++i){ dp[A[i]]=1; for(int div=2;div*div<=A[i];++div){ if(A[i]%div!=0)continue; dp[A[i]]=Math.max(dp[A[i]],dp[div]+1); dp[A[i]]=Math.max(dp[A[i]],dp[A[i]/div]+1); } if(A[i]>1)dp[A[i]]=Math.max(dp[A[i]],dp[1]+1); } int ans=0; for(int v:dp)ans=Math.max(ans,v); System.out.println(ans); } void tr(Object...o){System.out.println(Arrays.deepToString(o));} } // OpenJDK reference: // http://openjdk.java.net/ // Java language references: // http://docs.oracle.com/javase