結果

問題 No.979 Longest Divisor Sequence
ユーザー 37zigen37zigen
提出日時 2020-04-13 04:29:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,740 ms / 2,000 ms
コード長 1,291 bytes
コンパイル時間 5,919 ms
コンパイル使用メモリ 85,024 KB
実行使用メモリ 102,088 KB
最終ジャッジ日時 2023-10-24 05:27:28
合計ジャッジ時間 11,177 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 179 ms
66,608 KB
testcase_01 AC 181 ms
66,564 KB
testcase_02 AC 185 ms
66,488 KB
testcase_03 AC 181 ms
66,656 KB
testcase_04 AC 181 ms
66,660 KB
testcase_05 AC 189 ms
66,672 KB
testcase_06 AC 186 ms
66,456 KB
testcase_07 AC 189 ms
66,656 KB
testcase_08 AC 193 ms
66,896 KB
testcase_09 AC 189 ms
66,596 KB
testcase_10 AC 298 ms
68,524 KB
testcase_11 AC 301 ms
68,888 KB
testcase_12 AC 299 ms
68,656 KB
testcase_13 AC 792 ms
92,224 KB
testcase_14 AC 1,740 ms
102,088 KB
testcase_15 AC 1,074 ms
86,544 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]=Integer.parseInt(sc.next());
            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