結果

問題 No.1536 仕切り直し
ユーザー 👑 kakel-sankakel-san
提出日時 2024-06-10 21:09:39
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 2,150 bytes
コンパイル時間 16,488 ms
コンパイル使用メモリ 168,840 KB
実行使用メモリ 208,740 KB
最終ジャッジ日時 2024-06-10 21:09:57
合計ジャッジ時間 11,267 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
31,104 KB
testcase_01 AC 50 ms
31,104 KB
testcase_02 AC 53 ms
32,908 KB
testcase_03 AC 57 ms
33,024 KB
testcase_04 AC 76 ms
39,296 KB
testcase_05 AC 82 ms
47,616 KB
testcase_06 AC 55 ms
32,512 KB
testcase_07 AC 55 ms
32,768 KB
testcase_08 AC 65 ms
38,272 KB
testcase_09 AC 69 ms
40,056 KB
testcase_10 AC 95 ms
55,040 KB
testcase_11 AC 65 ms
35,840 KB
testcase_12 AC 81 ms
208,740 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (89 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/

ソースコード

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();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m) = (c[0], c[1]);
        var a = NList;
        WriteLine(string.Join("\n", Walls(n, m, a).ans));
    }
    static (List<int> ans, long[][] dp) Walls(int n, int m, int[] a)
    {
        var dp = new long[m + 1][];
        for (var i = 0; i < dp.Length; ++i) dp[i] = new long[n + 1];
        for (var i = 0; i < dp.Length; ++i)
        {
            if (i == 0)
            {
                for (var j = 0; j < n; ++j) dp[i][j + 1] = dp[i][j] + a[j];
            }
            else
            {
                for (var j = 0; j < n; ++j)
                {
                    if (i % 2 == 0) dp[i][j + 1] = Math.Max(dp[i][j + 1], Math.Max(dp[i - 1][j], dp[i][j]) + a[j]);
                    else dp[i][j + 1] = Math.Max(dp[i][j + 1], Math.Max(dp[i - 1][j], dp[i][j]) - a[j]);
                }
            }
        }
        var ans = new List<int>();
        var line = 0;
        var mpos = 0L;
        for (var i = 0; i <= m; ++i) if (mpos < dp[i][n])
        {
            line = i;
            mpos = dp[i][n];
        }
        for (var j = n - 1; j >= 0; --j)
        {
            if (line % 2 == 0)
            {
                if (line > 0 && dp[line - 1][j] + a[j] == dp[line][j + 1])
                {
                    --line;
                    ans.Add(j);
                }
            }
            else
            {
                if (dp[line - 1][j] - a[j] == dp[line][j + 1])
                {
                    --line;
                    ans.Add(j);
                }
            }
        }
        ans.Reverse();
        while (ans.Count < m) ans.Add(n);
        return (ans, dp);
    }
}
0