結果
問題 |
No.979 Longest Divisor Sequence
|
ユーザー |
![]() |
提出日時 | 2020-01-30 21:31:00 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,477 bytes |
コンパイル時間 | 2,333 ms |
コンパイル使用メモリ | 105,344 KB |
実行使用メモリ | 47,360 KB |
最終ジャッジ日時 | 2024-09-16 03:57:32 |
合計ジャッジ時間 | 5,687 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 WA * 10 TLE * 1 -- * 2 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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); } }