結果

問題 No.979 Longest Divisor Sequence
ユーザー ngtkanangtkana
提出日時 2020-01-30 20:27:12
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,524 bytes
コンパイル時間 849 ms
コンパイル使用メモリ 68,312 KB
実行使用メモリ 33,040 KB
最終ジャッジ日時 2023-10-14 08:43:38
合計ジャッジ時間 4,472 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

public static class Program{
    static int ALim=300001;
    public static void Main() {
        List<int>primes=new List<int>();
        {
            bool[]sieve=new bool[ALim];
            int p=2;
            for(;p*p<ALim;p++)if(!sieve[p]){
                primes.Add(p);
                for(int x=p*p;x<ALim;x+=p){
                    sieve[x]=true;
                }
            }
            for(;p<ALim;p++)if(!sieve[p]){
                primes.Add(p);
            }
        }

        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]=n;
        }
        for(int i=0;i<n;i++){
            Chmin(ref dp[i],i);
        }

        int ans=0;
        bool ckd=true;
        while(ckd){
            ans++;
            ckd=false;
            for(int i=0;i<ALim;i++)exc[i]=n;
            foreach(int p in primes){
                for(int i=1;i*p<ALim;i++){
                    Chmin(ref dp[i*p],dp[i]);
                    Chmin(ref exc[i*p], dp[i]);
                }
            }
            for(int i=0;i<n;i++)dp[i]=n;
            for(int i=0;i<n;i++)if(exc[a[i]]<i){
                Chmin(ref dp[a[i]],i);
                ckd=true;
            }
        }
        Console.WriteLine(ans);
    }
    public static void Chmin(ref int x, int y){
        x=Math.Min(x,y);
    }
}
0