結果

問題 No.979 Longest Divisor Sequence
ユーザー mbanmban
提出日時 2020-03-12 14:13:10
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,141 bytes
コンパイル時間 2,490 ms
コンパイル使用メモリ 102,760 KB
実行使用メモリ 53,132 KB
最終ジャッジ日時 2023-08-11 08:01:50
合計ジャッジ時間 5,806 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
21,712 KB
testcase_01 AC 66 ms
21,652 KB
testcase_02 AC 64 ms
21,728 KB
testcase_03 AC 65 ms
23,744 KB
testcase_04 WA -
testcase_05 AC 65 ms
21,656 KB
testcase_06 AC 64 ms
21,688 KB
testcase_07 AC 64 ms
21,668 KB
testcase_08 AC 65 ms
21,668 KB
testcase_09 AC 64 ms
19,708 KB
testcase_10 AC 78 ms
22,764 KB
testcase_11 AC 78 ms
22,756 KB
testcase_12 AC 78 ms
24,680 KB
testcase_13 WA -
testcase_14 AC 591 ms
53,132 KB
testcase_15 AC 243 ms
29,428 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.Linq;
using CompLib.Util;

class Program
{
    private int N;
    private int[] A;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        A = sc.IntArray();


        var dp = new int[300001];
        foreach (int i in A)
        {
            dp[i] = Math.Max(dp[i], Math.Max(dp[1] + 1, 1));
            // iの約数
            for (int t = 2; t * t <= i; t++)
            {
                if (i % t == 0)
                {
                    dp[i] = Math.Max(dp[i], dp[t] + 1);
                    dp[i] = Math.Max(dp[i], dp[i / t] + 1);
                }
            }
        }

        Console.WriteLine(dp.Max());
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(' ');
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}
0