結果

問題 No.979 Longest Divisor Sequence
ユーザー 37zigen37zigen
提出日時 2020-02-01 00:50:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,913 ms / 2,000 ms
コード長 1,276 bytes
コンパイル時間 2,554 ms
コンパイル使用メモリ 80,416 KB
実行使用メモリ 105,604 KB
最終ジャッジ日時 2023-10-17 16:20:47
合計ジャッジ時間 10,439 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 181 ms
66,464 KB
testcase_01 AC 177 ms
66,628 KB
testcase_02 AC 178 ms
66,620 KB
testcase_03 AC 176 ms
66,596 KB
testcase_04 AC 181 ms
66,484 KB
testcase_05 AC 180 ms
66,584 KB
testcase_06 AC 179 ms
66,620 KB
testcase_07 AC 179 ms
66,528 KB
testcase_08 AC 180 ms
66,588 KB
testcase_09 AC 173 ms
66,620 KB
testcase_10 AC 296 ms
68,436 KB
testcase_11 AC 292 ms
68,452 KB
testcase_12 AC 285 ms
67,896 KB
testcase_13 AC 918 ms
96,608 KB
testcase_14 AC 1,913 ms
105,604 KB
testcase_15 AC 1,157 ms
89,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 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
0