結果

問題 No.390 最長の数列
ユーザー AreTrashAreTrash
提出日時 2016-09-04 18:56:47
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 728 ms / 5,000 ms
コード長 2,281 bytes
コンパイル時間 4,148 ms
コンパイル使用メモリ 113,724 KB
実行使用メモリ 43,916 KB
最終ジャッジ日時 2024-04-10 10:06:15
合計ジャッジ時間 5,176 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
24,212 KB
testcase_01 AC 49 ms
24,748 KB
testcase_02 AC 70 ms
24,344 KB
testcase_03 AC 54 ms
24,496 KB
testcase_04 AC 66 ms
26,416 KB
testcase_05 AC 79 ms
42,376 KB
testcase_06 AC 728 ms
43,916 KB
testcase_07 AC 49 ms
26,260 KB
testcase_08 AC 33 ms
24,340 KB
testcase_09 AC 50 ms
26,640 KB
testcase_10 AC 138 ms
42,920 KB
testcase_11 AC 151 ms
41,832 KB
testcase_12 AC 146 ms
42,088 KB
testcase_13 AC 155 ms
41,416 KB
testcase_14 AC 432 ms
41,036 KB
testcase_15 AC 32 ms
24,504 KB
testcase_16 AC 35 ms
24,636 KB
testcase_17 AC 48 ms
27,280 KB
testcase_18 AC 54 ms
25,520 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.Linq;

namespace No390{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var N = sr.Next<int>();
            var X = sr.Next<int>(N);

            var dic = new Dictionary<int, int>();
            Array.ForEach(X, x => dic.Add(x, 1));

            var res = 1;
            for(var i = 1; i <= 500000; i++){
                if(dic.ContainsKey(i)){
                    for(var j = i << 1; j <= 1000000; j += i){
                        if(dic.ContainsKey(j)){
                            dic[j] = Math.Max(dic[j], dic[i] + 1);
                            res = Math.Max(res, dic[j]);
                        }
                    }
                }
            }

            Console.WriteLine(res);
            //---------------------------------
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];
        private readonly System.IO.StreamReader _sr = new System.IO.StreamReader(Console.OpenStandardInput());

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = _sr.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var ret = new T[x];
            for(var i = 0; i < x; ++i) ret[i] = Next<T>();
            return ret;
        }

        public T[][] Next<T>(int y, int x){
            var ret = new T[y][];
            for(var i = 0; i < y; ++i) ret[i] = Next<T>(x);
            return ret;
        }
    }
}
0