結果

問題 No.979 Longest Divisor Sequence
ユーザー 37zigen37zigen
提出日時 2020-02-01 00:44:34
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,281 bytes
コンパイル時間 2,826 ms
コンパイル使用メモリ 79,660 KB
実行使用メモリ 117,884 KB
最終ジャッジ日時 2023-10-17 15:16:36
合計ジャッジ時間 11,475 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 TLE -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

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){
            for(int div=2;div*div<=A[i];++div){
                if(A[i]%div!=0)continue;
                tr(A[i],div,A[i]/div);
                dp[A[i]]=Math.max(dp[A[i]],dp[div]+1);
                dp[A[i]]=Math.max(dp[A[i]],dp[A[i]/div]+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