結果

問題 No.1330 Multiply or Divide
ユーザー さかぽん
提出日時 2021-01-08 22:12:06
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,132 bytes
コンパイル時間 3,004 ms
コンパイル使用メモリ 106,624 KB
実行使用メモリ 43,776 KB
最終ジャッジ日時 2024-11-16 12:37:25
合計ジャッジ時間 8,007 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 45 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Linq;

class B
{
	static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
	static (int, int) Read2() { var a = Read(); return (a[0], a[1]); }
	static (int, int, int) Read3() { var a = Read(); return (a[0], a[1], a[2]); }
	static long[] ReadL() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
	static void Main()
	{
		var (n, m, p) = Read3();
		var a = ReadL();

		var amax = a.Max();

		// p^j を含む a_i
		var pa = new long[32];
		// a_i / p^j
		var da = new long[32];

		foreach (var v in a)
		{
			var t = v;
			var j = 0;
			while (t % p == 0)
			{
				t /= p;
				j++;
			}
			pa[j] = Math.Max(pa[j], v);
			da[j] = Math.Max(da[j], t);
		}

		var dp = new long[100];
		dp[0] = 1;

		for (int i = 0; i < dp.Length - da.Length; i++)
		{
			var x = dp[i];
			if (x * amax > m)
			{
				Console.WriteLine(i + 1);
				return;
			}

			for (int j = 0; j < da.Length; j++)
			{
				dp[i + j + 1] = Math.Max(dp[i + j + 1], x * da[j]);
			}
		}
		Console.WriteLine(-1);
	}

	static long Gcd(long a, long b) { for (long r; (r = a % b) > 0; a = b, b = r) ; return b; }
}
0