結果

問題 No.1330 Multiply or Divide
ユーザー さかぽんさかぽん
提出日時 2021-01-09 11:29:40
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 969 bytes
コンパイル時間 957 ms
コンパイル使用メモリ 106,368 KB
実行使用メモリ 44,032 KB
最終ジャッジ日時 2024-04-28 18:50:28
合計ジャッジ時間 6,057 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
18,688 KB
testcase_01 AC 114 ms
37,376 KB
testcase_02 AC 27 ms
18,560 KB
testcase_03 AC 26 ms
18,688 KB
testcase_04 AC 26 ms
18,304 KB
testcase_05 AC 26 ms
18,688 KB
testcase_06 AC 94 ms
32,896 KB
testcase_07 AC 185 ms
36,992 KB
testcase_08 AC 138 ms
43,392 KB
testcase_09 AC 141 ms
43,264 KB
testcase_10 AC 137 ms
43,392 KB
testcase_11 AC 134 ms
43,520 KB
testcase_12 AC 138 ms
43,648 KB
testcase_13 AC 27 ms
18,432 KB
testcase_14 AC 27 ms
18,432 KB
testcase_15 AC 26 ms
18,688 KB
testcase_16 AC 27 ms
18,816 KB
testcase_17 AC 27 ms
18,432 KB
testcase_18 AC 133 ms
43,520 KB
testcase_19 AC 133 ms
43,264 KB
testcase_20 AC 133 ms
43,392 KB
testcase_21 AC 133 ms
43,648 KB
testcase_22 AC 134 ms
43,392 KB
testcase_23 AC 146 ms
44,032 KB
testcase_24 AC 26 ms
18,688 KB
testcase_25 AC 27 ms
18,560 KB
testcase_26 AC 26 ms
18,432 KB
testcase_27 AC 26 ms
18,432 KB
testcase_28 AC 26 ms
18,432 KB
testcase_29 AC 27 ms
18,432 KB
testcase_30 AC 26 ms
18,688 KB
testcase_31 AC 26 ms
18,816 KB
testcase_32 AC 27 ms
18,688 KB
testcase_33 AC 27 ms
18,816 KB
testcase_34 AC 105 ms
36,224 KB
testcase_35 AC 50 ms
23,424 KB
testcase_36 AC 98 ms
35,456 KB
testcase_37 AC 91 ms
34,176 KB
testcase_38 AC 66 ms
26,624 KB
testcase_39 AC 56 ms
23,948 KB
testcase_40 AC 60 ms
24,576 KB
testcase_41 AC 46 ms
21,632 KB
testcase_42 AC 88 ms
34,048 KB
testcase_43 AC 95 ms
34,816 KB
testcase_44 AC 95 ms
32,896 KB
testcase_45 AC 94 ms
32,896 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.Linq;

class B
{
	static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
	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 a_max = a.Max();

		// a_i / p^j
		// j + 1 回でこの値による乗算
		var da = new long[32];

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

		var dp = new long[1 << 10];
		dp[0] = 1;

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

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