結果

問題 No.390 最長の数列
ユーザー kuuso1kuuso1
提出日時 2016-07-08 23:05:48
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 637 ms / 5,000 ms
コード長 1,479 bytes
コンパイル時間 1,026 ms
コンパイル使用メモリ 115,816 KB
実行使用メモリ 39,480 KB
最終ジャッジ日時 2024-04-10 08:50:12
合計ジャッジ時間 5,713 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
23,092 KB
testcase_01 AC 31 ms
24,912 KB
testcase_02 AC 31 ms
25,180 KB
testcase_03 AC 31 ms
25,140 KB
testcase_04 AC 30 ms
25,040 KB
testcase_05 AC 626 ms
39,480 KB
testcase_06 AC 637 ms
38,992 KB
testcase_07 AC 28 ms
26,868 KB
testcase_08 AC 29 ms
25,044 KB
testcase_09 AC 31 ms
27,160 KB
testcase_10 AC 500 ms
37,024 KB
testcase_11 AC 506 ms
39,196 KB
testcase_12 AC 499 ms
39,072 KB
testcase_13 AC 327 ms
35,884 KB
testcase_14 AC 280 ms
36,992 KB
testcase_15 AC 29 ms
27,252 KB
testcase_16 AC 31 ms
25,392 KB
testcase_17 AC 57 ms
25,936 KB
testcase_18 AC 72 ms
26,196 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		Array.Sort(A);
		Array.Reverse(A);
		
		Dictionary<int,int> D = new Dictionary<int,int>();
		for(int i=0;i<N;i++){
			D.Add(A[i],i);
		}
		
		int[] dp = new int[N];
		for(int i=0;i<N;i++)dp[i] = 1;
		for(int i=0;i<N;i++){
			for(int j=1;j*j<=A[i];j++){
				if(A[i] % j == 0){
					if(j != A[i] && D.ContainsKey(j))dp[D[j]] = Math.Max(dp[D[j]],dp[i] +1);
					int k = A[i]/j;
					if(k != A[i] && j != k && D.ContainsKey(k))dp[D[k]] = Math.Max(dp[D[k]],dp[i] +1);
				}
			}
//Console.WriteLine(String.Join(" ",dp));
		}
		Console.WriteLine(dp.Max());
		
		
		
	}
	int N;
	int[] A;
	public Sol(){
		N = ri();
		A = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
0