結果
| 問題 | No.2542 Yokan for Two |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-11-24 21:49:37 |
| 言語 | C# (.NET 10.0.201) |
| 結果 |
AC
|
| 実行時間 | 107 ms / 2,000 ms |
| コード長 | 1,123 bytes |
| 記録 | |
| コンパイル時間 | 6,639 ms |
| コンパイル使用メモリ | 173,784 KB |
| 実行使用メモリ | 199,416 KB |
| 最終ジャッジ日時 | 2026-04-13 12:21:01 |
| 合計ジャッジ時間 | 11,472 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (91 ミリ秒)。 main -> /home/judge/data/code/bin/Release/net10.0/main.dll main -> /home/judge/data/code/bin/Release/net10.0/publish/
ソースコード
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 (l, n) = (c[0], c[1]);
var x = NList;
var dp = new bool[l * 2 + 1];
dp[x[0] + x[^1]] = true;
for (var i = 1; i < x.Length; ++i)
{
var ndp = new bool[dp.Length];
for (var j = 0; j < dp.Length; ++j)
{
var nj = j + x[i] - x[i - 1];
if (nj >= 0 && nj < ndp.Length) ndp[nj] |= dp[j];
nj = j - x[i] + x[i - 1];
if (nj >= 0 && nj < ndp.Length) ndp[nj] |= dp[j];
}
dp = ndp;
}
for (var i = 0; i <= l; ++i)
{
if (dp[l + i] || dp[l - i])
{
WriteLine(i);
return;
}
}
}
}