結果

問題 No.1947 質より種類数
ユーザー masayamatumasayamatu
提出日時 2022-06-17 18:01:08
言語 C#
(.NET 8.0.203)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,234 bytes
コンパイル時間 14,405 ms
コンパイル使用メモリ 170,140 KB
実行使用メモリ 580,656 KB
最終ジャッジ日時 2024-04-17 08:47:59
合計ジャッジ時間 25,699 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
30,464 KB
testcase_01 AC 54 ms
30,592 KB
testcase_02 AC 53 ms
30,208 KB
testcase_03 AC 55 ms
30,588 KB
testcase_04 AC 61 ms
33,408 KB
testcase_05 AC 56 ms
32,384 KB
testcase_06 AC 59 ms
33,148 KB
testcase_07 AC 61 ms
32,884 KB
testcase_08 AC 60 ms
33,280 KB
testcase_09 AC 71 ms
40,276 KB
testcase_10 AC 66 ms
37,564 KB
testcase_11 AC 94 ms
51,176 KB
testcase_12 AC 83 ms
45,156 KB
testcase_13 AC 65 ms
36,292 KB
testcase_14 AC 280 ms
141,308 KB
testcase_15 AC 169 ms
87,012 KB
testcase_16 AC 383 ms
191,388 KB
testcase_17 AC 495 ms
239,032 KB
testcase_18 AC 754 ms
402,720 KB
testcase_19 AC 717 ms
355,476 KB
testcase_20 AC 558 ms
274,596 KB
testcase_21 AC 602 ms
318,372 KB
testcase_22 AC 90 ms
47,460 KB
testcase_23 AC 320 ms
159,428 KB
testcase_24 AC 63 ms
34,496 KB
testcase_25 AC 61 ms
33,596 KB
testcase_26 AC 59 ms
31,872 KB
testcase_27 AC 59 ms
32,896 KB
testcase_28 AC 62 ms
33,664 KB
testcase_29 AC 946 ms
423,836 KB
testcase_30 AC 955 ms
423,828 KB
testcase_31 AC 53 ms
30,208 KB
testcase_32 AC 54 ms
30,196 KB
testcase_33 AC 56 ms
30,976 KB
testcase_34 AC 731 ms
423,832 KB
testcase_35 AC 726 ms
423,956 KB
testcase_36 MLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (95 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 long[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