結果

問題 No.390 最長の数列
ユーザー bluemeganebluemegane
提出日時 2021-04-30 11:24:24
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 954 bytes
コンパイル時間 1,095 ms
コンパイル使用メモリ 61,324 KB
実行使用メモリ 31,340 KB
最終ジャッジ日時 2023-09-25 12:09:20
合計ジャッジ時間 4,082 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
20,716 KB
testcase_01 AC 58 ms
22,760 KB
testcase_02 WA -
testcase_03 AC 58 ms
20,724 KB
testcase_04 AC 59 ms
20,536 KB
testcase_05 AC 121 ms
29,252 KB
testcase_06 AC 107 ms
29,128 KB
testcase_07 AC 56 ms
20,688 KB
testcase_08 AC 58 ms
24,072 KB
testcase_09 AC 62 ms
24,148 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 108 ms
28,336 KB
testcase_14 AC 119 ms
27,136 KB
testcase_15 AC 58 ms
20,812 KB
testcase_16 AC 61 ms
24,008 KB
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        getAns(n, a);
    }
    static void getAns(int n, int[] a)
    {
        var ans = 0;
        Array.Sort(a);
        var amax = a[n - 1];
        var b = new bool[amax + 1];
        var used = new bool[amax + 1];
        for (int i = 0; i < n; i++) b[a[i]] = true;
        for (int i = 0; i < n; i++)
        {
            if (used[a[i]]) continue;
            var p = a[i];
            var count = 0;
            {
                while (p <= amax)
                {
                    if (b[p]) { count++; used[p] = true; p += p; }
                    else p += a[i];
                }
            }
            ans = Max(ans, count);
        }
        Console.WriteLine(ans);
    }
}
0