結果

問題 No.1330 Multiply or Divide
ユーザー kakel-san
提出日時 2024-08-22 23:44:39
言語 C#
(.NET 8.0.404)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 1,334 bytes
コンパイル時間 10,325 ms
コンパイル使用メモリ 169,804 KB
実行使用メモリ 202,548 KB
最終ジャッジ日時 2025-06-20 02:17:17
合計ジャッジ時間 15,766 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 51
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (117 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

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

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m, p) = (c[0], c[1], c[2]);
        var a = NList;
        var max = a.Max();
        var mul = new int[31];
        foreach (var ai in a)
        {
            var tmp = ai;
            var count = 1;
            while (tmp % p == 0)
            {
                tmp /= p;
                ++count;
            }
            if (tmp > 1) mul[count] = Math.Max(mul[count], tmp);
        }
        var dp = new long[1000];
        dp[0] = 1;
        for (var i = 0; i < dp.Length; ++i)
        {
            if (dp[i] * max > m)
            {
                WriteLine(i + 1);
                return;
            }
            for (var j = 1; j < mul.Length && i + j < dp.Length; ++j) if (mul[j] > 0)
            {
                dp[i + j] = Math.Max(dp[i + j], dp[i] * mul[j]);
            }
        }
        WriteLine(-1);
    }
}
0