結果

問題 No.2039 Copy and Avoid
ユーザー 👑 kakel-sankakel-san
提出日時 2023-10-24 22:21:14
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,826 bytes
コンパイル時間 16,945 ms
コンパイル使用メモリ 159,928 KB
実行使用メモリ 176,488 KB
最終ジャッジ日時 2023-10-24 22:21:36
合計ジャッジ時間 10,826 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
31,868 KB
testcase_01 AC 76 ms
30,820 KB
testcase_02 AC 79 ms
31,632 KB
testcase_03 AC 79 ms
30,812 KB
testcase_04 AC 76 ms
30,812 KB
testcase_05 AC 80 ms
31,804 KB
testcase_06 AC 75 ms
30,812 KB
testcase_07 AC 76 ms
30,812 KB
testcase_08 AC 76 ms
30,812 KB
testcase_09 AC 75 ms
30,812 KB
testcase_10 AC 75 ms
30,820 KB
testcase_11 AC 75 ms
30,820 KB
testcase_12 AC 77 ms
31,212 KB
testcase_13 AC 129 ms
31,860 KB
testcase_14 AC 105 ms
31,860 KB
testcase_15 AC 103 ms
31,860 KB
testcase_16 AC 102 ms
31,860 KB
testcase_17 AC 79 ms
31,804 KB
testcase_18 AC 79 ms
31,804 KB
testcase_19 AC 79 ms
31,812 KB
testcase_20 AC 81 ms
31,812 KB
testcase_21 AC 76 ms
30,828 KB
testcase_22 AC 75 ms
30,828 KB
testcase_23 AC 79 ms
30,828 KB
testcase_24 AC 76 ms
30,828 KB
testcase_25 AC 84 ms
30,828 KB
testcase_26 AC 76 ms
30,828 KB
testcase_27 AC 77 ms
31,228 KB
testcase_28 AC 76 ms
30,828 KB
testcase_29 AC 75 ms
30,820 KB
testcase_30 AC 75 ms
176,488 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (146 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.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, a, b) = (c[0], c[1], c[2], c[3]);
        c = NList;
        var plist = PList(n);
        var INF = long.MaxValue / 2;
        var len = Enumerable.Repeat(INF, plist.Count).ToArray();
        len[0] = 0;
        for (var i = 0; i < plist.Count; ++i)
        {
            var minci = int.MaxValue;
            foreach (var ci in c) if (ci % plist[i] == 0)
            {
                minci = ci;
                break;
            }
            for (var j = i + 1; j < plist.Count; ++j)
            {
                if (minci <= plist[j]) break;
                if (plist[j] % plist[i] == 0)
                {
                    if (j + 1 == plist.Count) len[j] = Math.Min(len[j], len[i] + (long)(plist[j] / plist[i] - 1) * a);
                    else len[j] = Math.Min(len[j], len[i] + (long)(plist[j] / plist[i] - 1) * a + b);
                }
            }
        }
        WriteLine(len.Last() == INF ? -1 : len.Last());
    }
    static List<int> PList(int n)
    {
        var ans = new List<int>();
        var rev = new List<int>();
        for (var i = 1; i * i <= n; ++i)
        {
            if (n % i == 0)
            {
                ans.Add(i);
                if (i * i < n) rev.Add(n / i);
            }
        }
        rev.Reverse();
        return ans.Concat(rev).ToList();
    }
}
0