結果

問題 No.979 Longest Divisor Sequence
ユーザー 37zigen37zigen
提出日時 2020-02-01 00:48:03
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,242 bytes
コンパイル時間 4,131 ms
コンパイル使用メモリ 79,668 KB
実行使用メモリ 105,856 KB
最終ジャッジ日時 2023-10-17 16:03:59
合計ジャッジ時間 10,710 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 182 ms
66,596 KB
testcase_01 AC 182 ms
66,692 KB
testcase_02 AC 180 ms
66,564 KB
testcase_03 AC 179 ms
66,788 KB
testcase_04 WA -
testcase_05 AC 184 ms
66,664 KB
testcase_06 AC 183 ms
66,892 KB
testcase_07 AC 182 ms
66,668 KB
testcase_08 AC 188 ms
66,452 KB
testcase_09 AC 180 ms
66,696 KB
testcase_10 AC 305 ms
68,668 KB
testcase_11 AC 302 ms
68,660 KB
testcase_12 AC 312 ms
68,696 KB
testcase_13 WA -
testcase_14 TLE -
testcase_15 AC 1,208 ms
89,420 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){
            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);
            }
            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