結果

問題 No.1947 質より種類数
ユーザー masayamatumasayamatu
提出日時 2022-06-17 18:03:20
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 757 ms / 2,000 ms
コード長 2,233 bytes
コンパイル時間 7,429 ms
コンパイル使用メモリ 166,788 KB
実行使用メモリ 382,988 KB
最終ジャッジ日時 2024-04-17 08:49:46
合計ジャッジ時間 16,942 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
30,080 KB
testcase_01 AC 53 ms
30,464 KB
testcase_02 AC 54 ms
30,336 KB
testcase_03 AC 56 ms
30,464 KB
testcase_04 AC 64 ms
32,760 KB
testcase_05 AC 61 ms
31,744 KB
testcase_06 AC 61 ms
32,000 KB
testcase_07 AC 63 ms
32,380 KB
testcase_08 AC 63 ms
32,384 KB
testcase_09 AC 72 ms
36,044 KB
testcase_10 AC 69 ms
34,632 KB
testcase_11 AC 94 ms
41,580 KB
testcase_12 AC 82 ms
38,500 KB
testcase_13 AC 66 ms
33,952 KB
testcase_14 AC 226 ms
86,784 KB
testcase_15 AC 142 ms
59,328 KB
testcase_16 AC 294 ms
111,636 KB
testcase_17 AC 376 ms
135,712 KB
testcase_18 AC 674 ms
217,744 KB
testcase_19 AC 545 ms
194,048 KB
testcase_20 AC 426 ms
153,616 KB
testcase_21 AC 546 ms
175,772 KB
testcase_22 AC 82 ms
39,400 KB
testcase_23 AC 249 ms
95,804 KB
testcase_24 AC 65 ms
32,896 KB
testcase_25 AC 62 ms
32,512 KB
testcase_26 AC 57 ms
31,360 KB
testcase_27 AC 60 ms
32,256 KB
testcase_28 AC 64 ms
32,632 KB
testcase_29 AC 724 ms
228,624 KB
testcase_30 AC 757 ms
228,488 KB
testcase_31 AC 54 ms
30,592 KB
testcase_32 AC 55 ms
30,208 KB
testcase_33 AC 57 ms
31,232 KB
testcase_34 AC 537 ms
228,488 KB
testcase_35 AC 544 ms
228,376 KB
testcase_36 AC 754 ms
382,988 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (91 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 System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
//using static CompLib.CompLib;
//using DataStructure;

namespace atcoder
{

    class Program
    {
        const int intMax = 1000000000;
        const long longMax = 2000000000000000000;
        static void Main(string[] args)
        {
            var NVC = Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
            int N = NVC[0];
            int V = NVC[1];
            int C = NVC[2];
            var items = new (int, int)[2 * N];
            for (int i = 0; i < 2 * N; i++)
            {
                if (i % 2 == 0)
                {
                    var read = Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
                    items[i] = (read[0], read[1] + C);
                }
                else
                {
                    items[i] = (items[i - 1].Item1, items[i - 1].Item2 - C);
                }
            }
            var dp = new int[2 * N + 1, V + 1];
            for (int i = 0; i < 2 * N; i++)
            {
                for (int j = 0; j <= V; j++)
                {
                    if (i >= 1)
                        dp[i, j] = Math.Max(dp[i, j], dp[i - 1, j]);
                    if (i % 2 == 0)
                    {
                        if (j - items[i].Item1 >= 0)
                        {
                            if (i > 0)
                                dp[i, j] = Math.Max(dp[i, j], dp[i - 1, j - items[i].Item1] + items[i].Item2);
                            else
                            {
                                dp[i, j] = items[i].Item2;
                            }
                        }

                    }
                    else
                    {
                        if (j - items[i].Item1 >= 0)
                            dp[i, j] = Math.Max(dp[i, j], dp[i, j - items[i].Item1] + items[i].Item2);
                    }
                }
            }
            long ans = 0;
            for (int i = 0; i <= V; i++)
            {
                ans = Math.Max(ans, dp[2 * N - 1, i]);
            }
            Console.WriteLine(ans);
        }
    }
}
0