結果

問題 No.1731 Product of Subsequence
ユーザー 👑 kakel-sankakel-san
提出日時 2021-11-05 22:24:34
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,606 bytes
コンパイル時間 902 ms
コンパイル使用メモリ 114,024 KB
実行使用メモリ 43,904 KB
最終ジャッジ日時 2024-04-24 06:14:34
合計ジャッジ時間 6,498 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 289 ms
39,040 KB
testcase_01 AC 29 ms
19,456 KB
testcase_02 AC 30 ms
19,328 KB
testcase_03 AC 30 ms
19,328 KB
testcase_04 AC 29 ms
19,200 KB
testcase_05 AC 30 ms
19,328 KB
testcase_06 AC 29 ms
19,584 KB
testcase_07 AC 30 ms
19,072 KB
testcase_08 AC 43 ms
20,096 KB
testcase_09 WA -
testcase_10 AC 294 ms
38,144 KB
testcase_11 AC 261 ms
41,088 KB
testcase_12 AC 36 ms
20,224 KB
testcase_13 AC 41 ms
20,608 KB
testcase_14 AC 250 ms
43,904 KB
testcase_15 AC 30 ms
19,456 KB
testcase_16 WA -
testcase_17 AC 30 ms
19,328 KB
testcase_18 AC 397 ms
38,144 KB
testcase_19 AC 38 ms
20,608 KB
testcase_20 AC 319 ms
42,496 KB
testcase_21 AC 289 ms
38,016 KB
testcase_22 AC 193 ms
38,272 KB
testcase_23 WA -
testcase_24 AC 46 ms
20,736 KB
testcase_25 AC 39 ms
20,352 KB
testcase_26 AC 78 ms
23,936 KB
testcase_27 AC 99 ms
24,116 KB
testcase_28 AC 157 ms
24,236 KB
testcase_29 AC 80 ms
23,712 KB
testcase_30 AC 243 ms
37,888 KB
testcase_31 AC 204 ms
38,272 KB
testcase_32 WA -
testcase_33 AC 48 ms
21,888 KB
testcase_34 AC 49 ms
21,504 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 long[] NList => ReadLine().Split().Select(long.Parse).ToArray();
    static void Main()
    {
        var c = NList;
        var (n, k) = ((int)c[0], c[1]);
        var a = NList;

        var gcda = new long[n];
        for (var i = 0; i < n; ++i) gcda[i] = GCD(k, a[i]);

        var key = 1000000007;
        var divs = Divs(k);
        var dic = new Dictionary<long, int>();
        for (var i = 0; i < divs.Count; ++i) dic[divs[i]] = i;
        var dp = new long[divs.Count];
        dp[0] = 1;
        for (var i = 0; i < n; ++i)
        {
            var next = (long[]) dp.Clone();
            for (var j = 0; j < dp.Length; ++j)
            {
                var nj = dic[GCD(gcda[i] * divs[j], k)];
                next[nj] = (next[nj] + dp[j]) % key;
            }
            dp = next;
        }
        WriteLine(dp.Last());
    }
    static long GCD(long a, long b)
    {
        if (a < b) return GCD(b, a);
        if (a % b == 0) return b;
        return GCD(b, a % b);
    }
    static List<long> Divs(long a)
    {
        var list = new List<long>();
        var rev = new List<long>();
        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