結果

問題 No.979 Longest Divisor Sequence
ユーザー ngtkanangtkana
提出日時 2020-01-30 21:44:29
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,028 bytes
コンパイル時間 843 ms
コンパイル使用メモリ 68,040 KB
実行使用メモリ 52,072 KB
最終ジャッジ日時 2023-10-14 08:50:58
合計ジャッジ時間 3,828 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
23,332 KB
testcase_01 AC 95 ms
23,220 KB
testcase_02 AC 105 ms
23,296 KB
testcase_03 AC 105 ms
23,328 KB
testcase_04 WA -
testcase_05 AC 108 ms
23,280 KB
testcase_06 AC 122 ms
23,388 KB
testcase_07 AC 107 ms
23,384 KB
testcase_08 WA -
testcase_09 AC 107 ms
23,276 KB
testcase_10 AC 130 ms
23,576 KB
testcase_11 AC 130 ms
25,528 KB
testcase_12 AC 129 ms
21,504 KB
testcase_13 WA -
testcase_14 AC 357 ms
52,072 KB
testcase_15 AC 224 ms
30,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public static class Program{
    static int ALim=300001;
    public static void Main() {
        int n=int.Parse(Console.ReadLine());
        int[]a=Console.ReadLine().Split().Select(int.Parse).ToArray();

        int[]dp=new int[ALim];
        int[]exc=new int[ALim];
        for(int i=0;i<ALim;i++){
            dp[i]=-1;
        }
        int ans=0;
        while(true){
            bool found=false;

            for(int i=0;i<ALim;i++)exc[i]=n;
            for(int i=1;i<ALim;i++){
                for(int j=2*i;j<ALim;j+=i){
                    Chmin(ref exc[j], dp[i]);
                }
            }

            for(int i=0;i<ALim;i++)dp[i]=n;
            for(int i=0;i<n;i++)if(exc[a[i]]<i){
                Chmin(ref dp[a[i]],i);
                found=true;
            }
            if(!found)break;
            ans++;
        }
        Console.WriteLine(ans);
    }
    public static void Chmin(ref int x, int y){
        x=Math.Min(x,y);
    }
}
0