結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー 👑 kakel-sankakel-san
提出日時 2021-11-05 22:05:05
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,916 ms / 2,000 ms
コード長 1,284 bytes
コンパイル時間 1,667 ms
コンパイル使用メモリ 67,920 KB
実行使用メモリ 48,808 KB
最終ジャッジ日時 2023-08-07 23:07:42
合計ジャッジ時間 17,208 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,916 ms
43,204 KB
testcase_01 AC 68 ms
21,664 KB
testcase_02 AC 67 ms
21,612 KB
testcase_03 AC 69 ms
23,972 KB
testcase_04 AC 70 ms
21,956 KB
testcase_05 AC 69 ms
22,036 KB
testcase_06 AC 69 ms
21,992 KB
testcase_07 AC 70 ms
24,112 KB
testcase_08 AC 69 ms
23,740 KB
testcase_09 AC 69 ms
21,724 KB
testcase_10 AC 75 ms
21,824 KB
testcase_11 AC 67 ms
21,632 KB
testcase_12 AC 67 ms
21,712 KB
testcase_13 AC 802 ms
46,836 KB
testcase_14 AC 803 ms
48,788 KB
testcase_15 AC 808 ms
48,808 KB
testcase_16 AC 804 ms
46,768 KB
testcase_17 AC 803 ms
46,864 KB
testcase_18 AC 516 ms
43,952 KB
testcase_19 AC 984 ms
45,484 KB
testcase_20 AC 464 ms
39,692 KB
testcase_21 AC 468 ms
39,532 KB
testcase_22 AC 1,767 ms
45,456 KB
testcase_23 AC 175 ms
37,620 KB
testcase_24 AC 175 ms
35,672 KB
testcase_25 AC 731 ms
44,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;

class yuki321
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static void Main()
    {
        var n = NN;
        var a = NList;
        var gcds = new int[1000001];
        foreach (var ai in a) foreach (var div in Divs(ai))
        {
            ++gcds[div];
        }
        var counts = new int[n + 1];
        for (var i = 0; i < gcds.Length; ++i)
        {
            counts[gcds[i]] = i;
        }
        for (var i = counts.Length - 2; i >= 0; --i)
        {
            counts[i] = Math.Max(counts[i + 1], counts[i]);
        }
        var res = new List<int>(n);
        for (var i = n; i > 0; --i) res.Add(counts[i]);
        WriteLine(string.Join("\n", res));
    }
    static List<int> Divs(int a)
    {
        var list = new List<int>();
        var rev = new List<int>();
        for (var i = 1; i * i <= a; ++i)
        {
            if (a % i == 0)
            {
                list.Add(i);
                if (i * i < a) rev.Add(a / i);
            }
        }
        rev.Reverse();
        list.AddRange(rev);
        return list;
    }
}
0