結果

問題 No.979 Longest Divisor Sequence
ユーザー mbanmban
提出日時 2020-03-12 14:14:59
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 707 ms / 2,000 ms
コード長 2,264 bytes
コンパイル時間 2,336 ms
コンパイル使用メモリ 105,428 KB
実行使用メモリ 52,148 KB
最終ジャッジ日時 2023-08-11 08:05:49
合計ジャッジ時間 5,395 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
23,704 KB
testcase_01 AC 67 ms
21,800 KB
testcase_02 AC 67 ms
23,812 KB
testcase_03 AC 66 ms
23,612 KB
testcase_04 AC 67 ms
21,596 KB
testcase_05 AC 68 ms
21,808 KB
testcase_06 AC 66 ms
21,860 KB
testcase_07 AC 67 ms
21,632 KB
testcase_08 AC 66 ms
21,716 KB
testcase_09 AC 68 ms
23,912 KB
testcase_10 AC 81 ms
22,564 KB
testcase_11 AC 83 ms
22,708 KB
testcase_12 AC 84 ms
24,816 KB
testcase_13 AC 145 ms
42,808 KB
testcase_14 AC 707 ms
52,148 KB
testcase_15 AC 279 ms
29,340 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)
        {
            if (i == 1)
            {
                dp[i] = Math.Max(dp[i], 1);
                continue;
            }

            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