結果

問題 No.390 最長の数列
ユーザー 14番14番
提出日時 2016-07-19 02:17:09
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,794 ms / 5,000 ms
コード長 2,828 bytes
コンパイル時間 947 ms
コンパイル使用メモリ 114,536 KB
実行使用メモリ 118,980 KB
最終ジャッジ日時 2024-04-10 09:12:53
合計ジャッジ時間 5,379 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
27,756 KB
testcase_01 AC 33 ms
23,480 KB
testcase_02 AC 34 ms
25,720 KB
testcase_03 AC 32 ms
25,712 KB
testcase_04 AC 35 ms
25,772 KB
testcase_05 AC 148 ms
51,464 KB
testcase_06 AC 1,794 ms
118,980 KB
testcase_07 AC 32 ms
25,396 KB
testcase_08 AC 33 ms
25,716 KB
testcase_09 AC 35 ms
25,332 KB
testcase_10 AC 226 ms
56,000 KB
testcase_11 AC 227 ms
55,364 KB
testcase_12 AC 224 ms
57,276 KB
testcase_13 AC 170 ms
51,408 KB
testcase_14 AC 494 ms
75,020 KB
testcase_15 AC 31 ms
25,716 KB
testcase_16 AC 34 ms
25,772 KB
testcase_17 AC 43 ms
26,744 KB
testcase_18 AC 45 ms
28,984 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.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();
    }
}
0