結果

問題 No.1861 Required Number
ユーザー 👑 kakel-sankakel-san
提出日時 2022-03-04 23:11:24
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 202 ms / 2,500 ms
コード長 1,745 bytes
コンパイル時間 860 ms
コンパイル使用メモリ 66,044 KB
実行使用メモリ 49,576 KB
最終ジャッジ日時 2023-09-26 03:52:57
合計ジャッジ時間 11,894 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
21,820 KB
testcase_01 AC 62 ms
21,712 KB
testcase_02 AC 63 ms
21,724 KB
testcase_03 AC 202 ms
47,596 KB
testcase_04 AC 197 ms
49,576 KB
testcase_05 AC 63 ms
23,816 KB
testcase_06 AC 62 ms
21,800 KB
testcase_07 AC 61 ms
21,756 KB
testcase_08 AC 69 ms
21,872 KB
testcase_09 AC 63 ms
23,760 KB
testcase_10 AC 63 ms
23,744 KB
testcase_11 AC 63 ms
21,708 KB
testcase_12 AC 62 ms
21,736 KB
testcase_13 AC 62 ms
21,688 KB
testcase_14 AC 62 ms
19,616 KB
testcase_15 AC 63 ms
23,936 KB
testcase_16 AC 62 ms
23,748 KB
testcase_17 AC 62 ms
23,680 KB
testcase_18 AC 61 ms
21,768 KB
testcase_19 AC 63 ms
21,816 KB
testcase_20 AC 63 ms
23,864 KB
testcase_21 AC 62 ms
23,856 KB
testcase_22 AC 63 ms
21,680 KB
testcase_23 AC 62 ms
21,764 KB
testcase_24 AC 111 ms
32,084 KB
testcase_25 AC 171 ms
43,596 KB
testcase_26 AC 86 ms
24,156 KB
testcase_27 AC 106 ms
32,136 KB
testcase_28 AC 116 ms
35,356 KB
testcase_29 AC 98 ms
34,260 KB
testcase_30 AC 78 ms
20,488 KB
testcase_31 AC 170 ms
45,376 KB
testcase_32 AC 80 ms
26,536 KB
testcase_33 AC 144 ms
41,468 KB
testcase_34 AC 152 ms
36,900 KB
testcase_35 AC 154 ms
41,000 KB
testcase_36 AC 99 ms
27,844 KB
testcase_37 AC 111 ms
30,584 KB
testcase_38 AC 154 ms
38,632 KB
testcase_39 AC 119 ms
36,416 KB
testcase_40 AC 171 ms
41,548 KB
testcase_41 AC 172 ms
45,480 KB
testcase_42 AC 152 ms
43,208 KB
testcase_43 AC 111 ms
32,248 KB
testcase_44 AC 61 ms
19,780 KB
04_evil_1.txt MLE -
04_evil_2.txt MLE -
04_evil_3.txt MLE -
04_evil_4.txt MLE -
権限があれば一括ダウンロードができます

ソースコード

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 void Main()
    {
        var c = NList;
        var (n, k) = (c[0], c[1]);
        var a = NList;
        Array.Sort(a);

        var dp1 = new bool[n + 1][];
        for (var i = 0; i < dp1.Length; ++i) dp1[i] = new bool[k + 1];
        dp1[0][0] = true;
        for (var i = 0; i < n; ++i)
        {
            dp1[i + 1][0] = true;
            for (var j = 0; j <= k; ++j)
            {
                if (dp1[i][j])
                {
                    dp1[i + 1][j] = true;
                    if (j + a[i] <= k) dp1[i + 1][j + a[i]] = true;
                }
            }
        }
        if (!dp1[n][k])
        {
            WriteLine(-1);
            return;
        }
        var dp2 = new bool[n + 1][];
        for (var i = 0; i < dp2.Length; ++i) dp2[i] = new bool[k + 1];
        dp2[n][0] = true;
        for (var i = n - 1; i >= 0; --i)
        {
            for (var j = 0; j <= k; ++j)
            {
                if (dp2[i + 1][j])
                {
                    dp2[i][j] = true;
                    if (j + a[i] <= k) dp2[i][j + a[i]] = true;
                }
            }
        }
        var res = 0;
        for (var i = 0; i < n; ++i)
        {
            var flg = false;
            for (var j = 0; j <= k; ++j)
            {
                if (dp1[i][j] && dp2[i + 1][k - j])
                {
                    flg = true;
                    break;
                }
            }
            if (!flg) ++res;
        }
        WriteLine(res);
    }
}
0