結果
問題 | No.1330 Multiply or Divide |
ユーザー |
|
提出日時 | 2021-01-08 22:20:43 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 195 ms / 2,000 ms |
コード長 | 1,071 bytes |
コンパイル時間 | 2,981 ms |
コンパイル使用メモリ | 111,532 KB |
実行使用メモリ | 50,684 KB |
最終ジャッジ日時 | 2025-06-20 01:21:56 |
合計ジャッジ時間 | 9,125 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 51 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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[200]; dp[0] = 1; for (int i = 0; i < dp.Length - da.Length-20; i++) { var x = dp[i]; if (x * amax > 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); } }