結果
問題 | No.390 最長の数列 |
ユーザー |
![]() |
提出日時 | 2016-10-31 08:48:03 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 141 ms / 5,000 ms |
コード長 | 895 bytes |
コンパイル時間 | 4,035 ms |
コンパイル使用メモリ | 106,752 KB |
実行使用メモリ | 31,744 KB |
最終ジャッジ日時 | 2024-10-02 12:02:58 |
合計ジャッジ時間 | 2,920 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Magatro { static void Main() { int N = int.Parse(Console.ReadLine()); int[] x = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); Array.Sort(x); int A = x.Max(); int[] dp = (new int[A+1]).Select(q=>-1).ToArray(); for(int i = 0; i < N; i++) { dp[x[i]] = 1; } for(int i = 1; i <= A; i++) { if (dp[i] == -1) { continue; } for(int j = i + i; j <= A; j += i) { if (dp[j] != -1) { dp[j] = Math.Max(dp[i] + 1, dp[j]); } } } Console.Write(dp.Max()); } }