結果

問題 No.1872 Dictionary Order
ユーザー 👑 kakel-sankakel-san
提出日時 2023-11-29 00:08:48
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 205 ms / 2,000 ms
コード長 2,226 bytes
コンパイル時間 17,081 ms
コンパイル使用メモリ 158,956 KB
実行使用メモリ 180,496 KB
最終ジャッジ日時 2023-11-29 00:09:19
合計ジャッジ時間 16,561 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 161 ms
54,588 KB
testcase_01 AC 93 ms
34,468 KB
testcase_02 AC 152 ms
43,940 KB
testcase_03 AC 97 ms
35,876 KB
testcase_04 AC 205 ms
49,368 KB
testcase_05 AC 91 ms
34,724 KB
testcase_06 AC 127 ms
40,996 KB
testcase_07 AC 110 ms
37,796 KB
testcase_08 AC 83 ms
33,188 KB
testcase_09 AC 103 ms
36,900 KB
testcase_10 AC 113 ms
39,076 KB
testcase_11 AC 147 ms
43,428 KB
testcase_12 AC 99 ms
36,388 KB
testcase_13 AC 100 ms
36,388 KB
testcase_14 AC 143 ms
42,916 KB
testcase_15 AC 161 ms
44,964 KB
testcase_16 AC 91 ms
34,724 KB
testcase_17 AC 118 ms
39,588 KB
testcase_18 AC 121 ms
40,740 KB
testcase_19 AC 110 ms
38,436 KB
testcase_20 AC 101 ms
36,900 KB
testcase_21 AC 138 ms
41,508 KB
testcase_22 AC 187 ms
50,196 KB
testcase_23 AC 113 ms
40,356 KB
testcase_24 AC 101 ms
38,308 KB
testcase_25 AC 134 ms
43,300 KB
testcase_26 AC 99 ms
38,180 KB
testcase_27 AC 128 ms
43,044 KB
testcase_28 AC 164 ms
48,124 KB
testcase_29 AC 191 ms
49,544 KB
testcase_30 AC 85 ms
34,084 KB
testcase_31 AC 193 ms
51,740 KB
testcase_32 AC 82 ms
33,188 KB
testcase_33 AC 78 ms
32,548 KB
testcase_34 AC 83 ms
180,496 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (106 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) = (c[0], c[1]);
        var a = NList;
        var p = NList;
        WriteLine(Order(n, m, a, p));
    }
    static string Order(int n, int m, int[] a, int[] p)
    {
        var visited = new bool[n + 1, m + 1];
        visited[0, 0] = true;
        for (var i = 0; i < n; ++i) for (var j = 0; j <= m; ++j)
        {
            if (visited[i, j])
            {
                visited[i + 1, j] = true;
                if (j + a[i] <= m) visited[i + 1, j + a[i]] = true;
            }
        }
        if (!visited[n, m])
        {
            return "-1";
        }
        var next = new int[n + 1][];
        for (var i = 0; i < next.Length; ++i) next[i] = Enumerable.Repeat(-1, m + 1).ToArray();
        next[n][m] = 0;
        for (var j = m; j >= 0; --j) for (var i = n; i > 0; --i)
        {
            if (!visited[i, j]) continue;
            if (next[i][j] < 0) continue;
            if (visited[i - 1, j])
            {
                if (next[i - 1][j] == -1) next[i - 1][j] = next[i][j];
                else if (j < m && p[next[i - 1][j]] > p[next[i][j]]) next[i - 1][j] = next[i][j];
            }
            if (j - a[i - 1] >= 0 && visited[i - 1, j - a[i - 1]])
            {
                if (next[i - 1][j - a[i - 1]] == -1) next[i - 1][j - a[i - 1]] = i - 1;
                else if (p[next[i - 1][j - a[i - 1]]] > p[next[i][j]]) next[i - 1][j - a[i - 1]] = i - 1;
            }
        }
        var ans = new List<int>();
        var x = 0;
        var y = 0;
        while (y < m)
        {
            var b = next[x][y];
            ans.Add(b + 1);
            x = b + 1;
            y += a[b];
        }
        return $"{ans.Count}\n{string.Join(" ", ans)}";
    }
}
0