結果
| 問題 | No.2542 Yokan for Two | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-11-24 21:49:37 | 
| 言語 | C# (.NET 8.0.404) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 144 ms / 2,000 ms | 
| コード長 | 1,123 bytes | 
| コンパイル時間 | 8,444 ms | 
| コンパイル使用メモリ | 166,112 KB | 
| 実行使用メモリ | 188,128 KB | 
| 最終ジャッジ日時 | 2024-09-26 09:08:07 | 
| 合計ジャッジ時間 | 14,544 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 40 | 
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (102 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/
ソースコード
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;
            }
        }
    }
}
            
            
            
        