結果

問題 No.2313 Product of Subsequence (hard)
ユーザー dangodango
提出日時 2023-05-24 21:23:16
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 1,348 bytes
コンパイル時間 3,527 ms
コンパイル使用メモリ 104,316 KB
実行使用メモリ 65,764 KB
最終ジャッジ日時 2023-08-25 13:33:15
合計ジャッジ時間 15,602 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
24,016 KB
testcase_01 AC 56 ms
21,712 KB
testcase_02 AC 56 ms
22,060 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 59 ms
22,056 KB
testcase_23 RE -
testcase_24 AC 59 ms
19,848 KB
testcase_25 RE -
testcase_26 RE -
testcase_27 TLE -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 System.Linq;
class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n = input[0];
        int k = input[1];
        var a = Console.ReadLine().Split().Select(int.Parse).ToList();
        var dp = new List<Dictionary<int, int>>();
        for (int i = 0; i <= n; i++)
            dp.Add(new Dictionary<int, int>());
        dp[0][1] = 1;
        for (int x = 1; x <= n; x++)
        {
            int ai = Gcd(a[x - 1], k);
            foreach (var y in dp[x - 1].Keys.ToList())
            {
                if (!dp[x].ContainsKey(y))
                    dp[x][y] = 0;
                dp[x][y] += dp[x - 1][y];
                dp[x][y] %= 998244353;
                int z = Gcd(y * ai, k);
                if (!dp[x].ContainsKey(z))
                    dp[x][z] = 0;
                dp[x][z] += dp[x - 1][y];
                dp[x][z] %= 998244353;
            }
        }
        int ans = dp[n][k];
        if (k == 1)
            ans -= 1;
        Console.WriteLine(ans);
    }

    static int Gcd(int a, int b)
    {
        if (a < b)
            return Gcd(b, a);
        while (b != 0)
        {
            int r = a % b;
            a = b;
            b = r;
        }
        return a;
    }
}
0