結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー 👑 kakel-sankakel-san
提出日時 2021-11-05 22:05:05
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,928 ms / 2,000 ms
コード長 1,284 bytes
コンパイル時間 2,518 ms
コンパイル使用メモリ 113,508 KB
実行使用メモリ 52,808 KB
最終ジャッジ日時 2024-04-25 17:22:57
合計ジャッジ時間 17,350 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,928 ms
49,284 KB
testcase_01 AC 35 ms
27,400 KB
testcase_02 AC 35 ms
25,616 KB
testcase_03 AC 38 ms
25,368 KB
testcase_04 AC 38 ms
25,464 KB
testcase_05 AC 37 ms
25,368 KB
testcase_06 AC 37 ms
25,488 KB
testcase_07 AC 35 ms
25,432 KB
testcase_08 AC 35 ms
25,496 KB
testcase_09 AC 36 ms
27,384 KB
testcase_10 AC 40 ms
25,484 KB
testcase_11 AC 34 ms
25,116 KB
testcase_12 AC 34 ms
25,368 KB
testcase_13 AC 792 ms
50,764 KB
testcase_14 AC 788 ms
50,764 KB
testcase_15 AC 780 ms
50,628 KB
testcase_16 AC 779 ms
50,632 KB
testcase_17 AC 794 ms
52,808 KB
testcase_18 AC 493 ms
47,736 KB
testcase_19 AC 967 ms
47,504 KB
testcase_20 AC 456 ms
45,660 KB
testcase_21 AC 455 ms
45,532 KB
testcase_22 AC 1,747 ms
49,284 KB
testcase_23 AC 140 ms
41,384 KB
testcase_24 AC 141 ms
43,820 KB
testcase_25 AC 707 ms
48,048 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.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