結果

問題 No.2542 Yokan for Two
ユーザー heno239heno239
提出日時 2024-02-05 18:04:11
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 319 ms / 2,000 ms
コード長 1,726 bytes
コンパイル時間 6,934 ms
コンパイル使用メモリ 158,620 KB
実行使用メモリ 196,536 KB
最終ジャッジ日時 2024-02-05 18:04:30
合計ジャッジ時間 18,057 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
32,676 KB
testcase_01 AC 76 ms
32,676 KB
testcase_02 AC 75 ms
32,676 KB
testcase_03 AC 144 ms
49,092 KB
testcase_04 AC 117 ms
37,092 KB
testcase_05 AC 186 ms
47,524 KB
testcase_06 AC 80 ms
35,620 KB
testcase_07 AC 274 ms
47,956 KB
testcase_08 AC 132 ms
45,988 KB
testcase_09 AC 263 ms
47,840 KB
testcase_10 AC 100 ms
37,100 KB
testcase_11 AC 105 ms
36,900 KB
testcase_12 AC 161 ms
46,440 KB
testcase_13 AC 97 ms
37,132 KB
testcase_14 AC 287 ms
48,124 KB
testcase_15 AC 290 ms
48,724 KB
testcase_16 AC 285 ms
48,416 KB
testcase_17 AC 266 ms
48,564 KB
testcase_18 AC 294 ms
49,060 KB
testcase_19 AC 198 ms
46,100 KB
testcase_20 AC 170 ms
37,272 KB
testcase_21 AC 171 ms
37,284 KB
testcase_22 AC 173 ms
37,380 KB
testcase_23 AC 174 ms
37,412 KB
testcase_24 AC 93 ms
38,948 KB
testcase_25 AC 103 ms
41,380 KB
testcase_26 AC 102 ms
42,916 KB
testcase_27 AC 107 ms
42,916 KB
testcase_28 AC 107 ms
42,916 KB
testcase_29 AC 136 ms
47,524 KB
testcase_30 AC 298 ms
49,216 KB
testcase_31 AC 298 ms
53,796 KB
testcase_32 AC 314 ms
49,156 KB
testcase_33 AC 294 ms
49,204 KB
testcase_34 AC 290 ms
49,220 KB
testcase_35 AC 291 ms
49,204 KB
testcase_36 AC 291 ms
49,216 KB
testcase_37 AC 303 ms
49,092 KB
testcase_38 AC 298 ms
49,092 KB
testcase_39 AC 294 ms
49,860 KB
testcase_40 AC 319 ms
49,208 KB
testcase_41 AC 301 ms
53,028 KB
testcase_42 AC 299 ms
53,028 KB
testcase_43 AC 302 ms
196,536 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (96 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

using System.Collections;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

internal class Program
{
    private const long mod = 998244353;

    
    public static void Main(string[] args)
    {
        var line= Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int L = line[0], n = line[1];
        int [] x= Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var dpup = mkar(2 * L + 1, 0);
        dpup[L] = 1;
        var dpdow = mkar(2 * L + 1, 0);
        void upd(int len)
        {
            var ndpup = mkar(2 * L + 1, 0);
            var ndpdow = mkar(2 * L + 1, 0);
            for (int i = 0; i <= 2 * L; i++)
            {
                if (dpup[i]>0)
                {
                    ndpup[i + len] = ndpdow[i + len] = 1;
                }

                if (dpdow[i] > 0)
                {
                    ndpup[i - len] = ndpdow[i - len] = 1;
                }
            }

            dpup = ndpup;
            dpdow = ndpdow;
        }

        for (int i = 0; i < n; i++)
        {
            int len = x[i];
            if (i > 0) len -= x[i - 1];
            upd(len);
        }

        int ans = L;
        int las = L - x[n - 1];
        for (int i = 0; i <= 2 * L; i++)
        {
            if (dpdow[i]>0)
            {
                int val = i - las;
                val -= L;
                val = Math.Abs(val);
                ans = Math.Min(ans, val);
            }
        }
        Console.WriteLine(ans);
    }

    public static List<int> mkar(int n, int val)
    {
        List<int> res = new List<int>(n);
        for(int i=0;i<n;i++)res.Add(val);
        return res;
    }
}
0