結果

問題 No.979 Longest Divisor Sequence
ユーザー ngtkanangtkana
提出日時 2020-01-30 21:31:00
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,477 bytes
コンパイル時間 1,398 ms
コンパイル使用メモリ 67,984 KB
実行使用メモリ 30,320 KB
最終ジャッジ日時 2023-10-14 08:50:54
合計ジャッジ時間 6,793 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
30,320 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 96 ms
21,888 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 113 ms
23,912 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 TLE -
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;
            for(int i=1;i<ALim;i++){
                for(int j=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);
                ckd=true;
            }
        }
        Console.WriteLine(ans);
    }
    public static void Chmin(ref int x, int y){
        x=Math.Min(x,y);
    }
}
0