結果
| 問題 |
No.390 最長の数列
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-07-19 02:17:09 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 2,687 ms / 5,000 ms |
| コード長 | 2,828 bytes |
| コンパイル時間 | 2,330 ms |
| コンパイル使用メモリ | 120,188 KB |
| 実行使用メモリ | 110,708 KB |
| 最終ジャッジ日時 | 2024-10-02 11:00:19 |
| 合計ジャッジ時間 | 8,117 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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.Text;
using System.Linq;
class Program
{
public void Proc()
{
Reader.IsDebug = false;
int itemCount = int.Parse(Reader.ReadLine());
int[] items = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).OrderBy(a=>a).ToArray();
int max = items[items.Length - 1];
Dictionary<int, TreeNode> dic = new Dictionary<int, TreeNode>();
for(int i=0; i<items.Length; i++) {
dic.Add(items[i], new TreeNode(i, items[i]));
}
for(int i=0; i<items.Length; i++) {
int num = items[i];
TreeNode t = dic[num];
int tmp = max / num;
if(dic.Count > tmp) {
for(int j=2; j<=tmp; j++) {
if(dic.ContainsKey(num*j)) {
dic[num*j].Add(t);
}
}
} else {
for(int j=i+1; j<items.Length; j++) {
if(items[j] % num == 0) {
dic[items[j]].Add(t);
}
}
}
}
int ans = 0;
foreach (int key in dic.Keys)
{
ans = Math.Max(ans, dic[key].Length);
}
Console.WriteLine(ans);
}
public class TreeNode {
public int Number;
public int Index;
public List<TreeNode> Items = new List<TreeNode>();
public TreeNode Add(TreeNode child) {
this.Items.Add(child);
return child;
}
public int Length {
get {
if(this.LenValue == null) {
if(this.Items.Count == 0) {
this.LenValue = 1;
} else
{
this.LenValue = this.Items.Max(a=>a.Length) + 1;
}
}
return this.LenValue.Value;
}
}
private Nullable<int> LenValue = null;
public TreeNode(int idx, int num) {
this.Index = idx;
this.Number = num;
}
}
public class Reader
{
public static bool IsDebug = true;
private static String PlainInput = @"
7
1 2 22 88 8 4 440
";
private static System.IO.StringReader Sr = null;
public static string ReadLine()
{
if (IsDebug)
{
if (Sr == null)
{
Sr = new System.IO.StringReader(PlainInput.Trim());
}
return Sr.ReadLine();
}
else
{
return Console.ReadLine();
}
}
}
static void Main()
{
Program prg = new Program();
prg.Proc();
}
}
14番