結果
| 問題 |
No.979 Longest Divisor Sequence
|
| ユーザー |
mban
|
| 提出日時 | 2020-03-12 14:14:59 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 576 ms / 2,000 ms |
| コード長 | 2,264 bytes |
| コンパイル時間 | 3,142 ms |
| コンパイル使用メモリ | 110,680 KB |
| 実行使用メモリ | 55,780 KB |
| 最終ジャッジ日時 | 2024-11-17 22:27:21 |
| 合計ジャッジ時間 | 5,044 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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();
}
}
mban