結果
| 問題 |
No.2434 RAKUTAN de RAKUTAN
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-08-19 00:25:39 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 309 ms / 2,000 ms |
| コード長 | 2,060 bytes |
| コンパイル時間 | 5,635 ms |
| コンパイル使用メモリ | 114,412 KB |
| 実行使用メモリ | 72,320 KB |
| 最終ジャッジ日時 | 2024-11-28 12:29:13 |
| 合計ジャッジ時間 | 6,481 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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);
}
}