結果

問題 No.979 Longest Divisor Sequence
ユーザー ngtkanangtkana
提出日時 2020-01-30 20:08:02
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 642 ms / 2,000 ms
コード長 870 bytes
コンパイル時間 1,188 ms
コンパイル使用メモリ 66,208 KB
実行使用メモリ 52,016 KB
最終ジャッジ日時 2023-10-14 08:41:59
合計ジャッジ時間 3,901 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
21,652 KB
testcase_01 AC 54 ms
23,624 KB
testcase_02 AC 55 ms
21,632 KB
testcase_03 AC 53 ms
23,632 KB
testcase_04 AC 55 ms
21,668 KB
testcase_05 AC 54 ms
21,684 KB
testcase_06 AC 55 ms
21,588 KB
testcase_07 AC 56 ms
21,748 KB
testcase_08 AC 54 ms
23,680 KB
testcase_09 AC 56 ms
19,712 KB
testcase_10 AC 69 ms
22,544 KB
testcase_11 AC 66 ms
22,476 KB
testcase_12 AC 68 ms
24,472 KB
testcase_13 AC 132 ms
38,600 KB
testcase_14 AC 642 ms
52,016 KB
testcase_15 AC 257 ms
31,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Linq;
using System.Collections.Generic;

public static class Program{
    public static void Main() {
        int n=int.Parse(Console.ReadLine());
        int[]a=Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[]dp=new int[300001];
        for(int i=0;i<n;i++){
            int x=a[i];
            if(x==1){
                dp[1]=1;
                continue;
            }
            for(int d=1;d*d<=x;d++){
                if(x%d!=0)continue;
                Chmax(ref dp[x], dp[d]+1);
                if(d!=1){
                    Chmax(ref dp[x], dp[x/d]+1);
                }
            }
        }
        int ans=0;
        for(int i=0;i<=300000;i++){
            Chmax(ref ans, dp[i]);
        }
        Console.WriteLine(ans);
    }
    public static void Chmax(ref int x, int y){
        x=Math.Max(x,y);
    }
}
0