結果

問題 No.2866 yuusaan's Knapsack
ユーザー 👑 kakel-sankakel-san
提出日時 2024-08-30 22:05:50
言語 C#
(.NET 8.0.203)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,872 bytes
コンパイル時間 8,168 ms
コンパイル使用メモリ 170,920 KB
実行使用メモリ 190,752 KB
最終ジャッジ日時 2024-08-31 01:28:10
合計ジャッジ時間 10,262 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
32,896 KB
testcase_01 AC 61 ms
31,976 KB
testcase_02 AC 62 ms
33,528 KB
testcase_03 AC 63 ms
31,868 KB
testcase_04 AC 60 ms
31,744 KB
testcase_05 AC 60 ms
32,000 KB
testcase_06 AC 76 ms
37,248 KB
testcase_07 AC 73 ms
37,228 KB
testcase_08 AC 79 ms
37,504 KB
testcase_09 AC 78 ms
37,504 KB
testcase_10 AC 77 ms
37,504 KB
testcase_11 AC 77 ms
37,248 KB
testcase_12 AC 76 ms
37,228 KB
testcase_13 AC 73 ms
37,376 KB
testcase_14 AC 73 ms
37,376 KB
testcase_15 AC 76 ms
37,120 KB
testcase_16 AC 73 ms
37,236 KB
testcase_17 AC 77 ms
37,372 KB
testcase_18 AC 73 ms
37,248 KB
testcase_19 AC 81 ms
37,372 KB
testcase_20 AC 75 ms
37,248 KB
testcase_21 AC 73 ms
37,376 KB
testcase_22 AC 77 ms
37,248 KB
testcase_23 AC 84 ms
37,504 KB
testcase_24 AC 78 ms
37,376 KB
testcase_25 AC 82 ms
37,228 KB
testcase_26 AC 75 ms
37,504 KB
testcase_27 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (104 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.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, w) = (c[0], c[1]);
        var map = NArr(n);
        var dpv = new int[20001];
        var dpc = new long[20001];
        var dpe = new bool[20001];
        var mod = 998_244_353;
        dpc[10000] = 1;
        dpe[10000] = true;
        for (var i = 0; i < n; ++i)
        {
            var ndpv = (int[]) dpv.Clone();
            var ndpc = (long[]) dpc.Clone();
            var ndpe = (bool[]) dpe.Clone();
            for (var j = 0; j < dpv.Length; ++j)
            {
                if (!dpe[j]) continue;
                var to = j + map[i][1];
                if (to >= dpv.Length) break;
                if (!ndpe[to] || ndpv[to] < dpv[j] + map[i][0])
                {
                    ndpv[to] = dpv[j] + map[i][0];
                    ndpc[to] = dpc[j];
                    ndpe[to] = true;
                }
                else if (dpv[to] == dpv[j] + map[i][0])
                {
                    ndpc[to] = (dpc[to] + dpc[j]) % mod;
                }
            }
            dpv = ndpv;
            dpc = ndpc;
            dpe = ndpe;
        }
        var max = int.MinValue;
        for (var i = 0; i <= w + 10000; ++i) if (dpe[i]) max = Math.Max(max, dpv[i]);
        var count = 0L;
        for (var i = 0; i <= w + 10000; ++i) if (dpe[i] && dpv[i] == max) count = (count + dpc[i]) % mod;
        WriteLine($"{max} {count}");
    }
}
0