結果

問題 No.2434 RAKUTAN de RAKUTAN
ユーザー 👑 kakel-sankakel-san
提出日時 2023-08-19 00:25:39
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 305 ms / 2,000 ms
コード長 2,060 bytes
コンパイル時間 3,361 ms
コンパイル使用メモリ 114,300 KB
実行使用メモリ 72,320 KB
最終ジャッジ日時 2024-05-06 07:22:02
合計ジャッジ時間 6,545 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
19,072 KB
testcase_01 AC 32 ms
19,072 KB
testcase_02 AC 34 ms
19,072 KB
testcase_03 AC 36 ms
19,328 KB
testcase_04 AC 35 ms
19,328 KB
testcase_05 AC 35 ms
19,584 KB
testcase_06 AC 36 ms
19,456 KB
testcase_07 AC 33 ms
19,072 KB
testcase_08 AC 30 ms
18,688 KB
testcase_09 AC 30 ms
18,688 KB
testcase_10 AC 300 ms
72,192 KB
testcase_11 AC 304 ms
72,192 KB
testcase_12 AC 303 ms
72,064 KB
testcase_13 AC 304 ms
72,192 KB
testcase_14 AC 305 ms
72,320 KB
testcase_15 AC 36 ms
19,584 KB
testcase_16 AC 35 ms
19,584 KB
testcase_17 AC 35 ms
19,328 KB
testcase_18 AC 35 ms
19,584 KB
testcase_19 AC 34 ms
19,200 KB
testcase_20 AC 41 ms
20,404 KB
testcase_21 AC 41 ms
20,144 KB
testcase_22 AC 33 ms
19,200 KB
testcase_23 AC 33 ms
19,200 KB
testcase_24 AC 33 ms
19,072 KB
testcase_25 AC 33 ms
18,944 KB
testcase_26 AC 33 ms
18,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, h, x) = (c[0], c[1], c[2]);
        var g = NN;
        var glist = new int[0];
        if (g > 0) glist = NList;
        else ReadLine();
        var b = NN;
        var blist = new int[0];
        if (b > 0) blist = NList;
        else ReadLine();
        if (g + b == 0)
        {
            WriteLine(0);
            return;
        }
        var list = new List<(int pos, int val)>();
        foreach (var gi in glist) list.Add((gi, 1));
        foreach (var bi in blist) list.Add((bi, -1));
        list.Sort((l, r) => l.pos.CompareTo(r.pos));
        var cp = new List<int>();
        for (var i = 0; i < Math.Min(list[0].pos, x); ++i) cp.Add(0);
        cp.Add(list[0].val);
        for (var i = 1; i < list.Count; ++i)
        {
            for (var j = 0; j < Math.Min(list[i].pos - list[i - 1].pos - 1, x); ++j) cp.Add(0);
            cp.Add(list[i].val);
        }
        for (var i = 0; i < Math.Min(n - list.Last().pos, x); ++i) cp.Add(0);
        var dp = new int[cp.Count][];
        var INF = int.MinValue / 2;
        for (var i = 0; i < dp.Length; ++i) dp[i] = Enumerable.Repeat(INF, Math.Min(h + 1, b + 1)).ToArray();
        dp[0][0] = 0;
        for (var i = 0; i < dp.Length; ++i) for (var j = 0; j < dp[i].Length; ++j)
        {
            if (i + 1 < dp.Length) dp[i + 1][j] = Math.Max(dp[i + 1][j], dp[i][j] + cp[i + 1]);
            if (i + x < dp.Length && j + 1 < dp[i].Length) dp[i + x][j + 1] = Math.Max(dp[i + x][j + 1], dp[i][j] + cp[i + x]);
        }
        var ans = INF;
        for (var i = 0; i < dp[dp.Length - 1].Length; ++i) ans = Math.Max(ans, dp[dp.Length - 1][i]);
        WriteLine(ans);
    }
}
0