結果

問題 No.2232 Miser's Gift
ユーザー 👑 kakel-sankakel-san
提出日時 2023-07-25 07:23:52
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,496 bytes
コンパイル時間 880 ms
コンパイル使用メモリ 114,272 KB
実行使用メモリ 51,628 KB
最終ジャッジ日時 2024-04-10 00:50:43
合計ジャッジ時間 9,767 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
27,272 KB
testcase_01 AC 30 ms
25,472 KB
testcase_02 AC 30 ms
25,216 KB
testcase_03 AC 181 ms
47,088 KB
testcase_04 AC 128 ms
47,236 KB
testcase_05 AC 43 ms
31,156 KB
testcase_06 AC 30 ms
27,296 KB
testcase_07 AC 56 ms
35,544 KB
testcase_08 AC 194 ms
49,600 KB
testcase_09 AC 194 ms
47,412 KB
testcase_10 AC 192 ms
49,596 KB
testcase_11 AC 198 ms
47,676 KB
testcase_12 AC 199 ms
47,400 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

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 INF = long.MinValue;
        var init = Enumerable.Repeat(INF, w + 1).ToArray();
        var dp = (long[]) init.Clone();
        dp[0] = 0;
        for (var i = 0; i < n; ++i)
        {
            var ndp = (long[]) dp.Clone();
            for (var j = 0; j < dp.Length; ++j)
            {
                if (j + map[i][0] >= ndp.Length) break;
                ndp[j + map[i][0]] = Math.Max(ndp[j + map[i][0]], dp[j] + map[i][1]);
            }
            dp = ndp;
            // WriteLine(string.Join(" ", dp));
        }
        for (var i = 0; i < dp.Length; ++i) if (dp[i] < 0) dp[i] = dp[i - 1];
        var ans = new long[w];
        for (var i = 0; i < ans.Length; ++i) ans[i] = dp[w] - dp[w - i - 1] + 1;
        WriteLine(string.Join("\n", ans));
    }
    static long Exp(int n, int k, int mod)
    {
        if (k == 0) return 1;
        if (k == 1) return n % mod;
        var half = Exp(n, k / 2, mod);
        var result = (half * half) % mod;
        return ((k % 2) == 0) ? result : ((result * n) % mod);
    }
    class UnionFindTree
    {
        int[] roots;
        public UnionFindTree(int size)
        {
            roots = new int[size];
            for (var i = 0; i < size; ++i) roots[i] = -1;
        }
        public int GetRoot(int a)
        {
            if (roots[a] < 0) return a;
            return roots[a] = GetRoot(roots[a]);
        }
        public bool IsSameTree(int a, int b)
        {
            return GetRoot(a) == GetRoot(b);
        }
        public bool Unite(int a, int b)
        {
            var x = GetRoot(a);
            var y = GetRoot(b);
            if (x == y) return false;
            if (-roots[x] < -roots[y]) { var tmp = x; x = y; y = tmp; }
            roots[x] += roots[y];
            roots[y] = x;
            return true;
        }
        public int GetSize(int a)
        {
            return -roots[GetRoot(a)];
        }
    }
}
0