結果

問題 No.2095 High Rise
ユーザー 👑 kakel-sankakel-san
提出日時 2022-10-07 22:22:03
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 542 ms / 2,000 ms
コード長 1,710 bytes
コンパイル時間 1,575 ms
コンパイル使用メモリ 70,592 KB
実行使用メモリ 51,948 KB
最終ジャッジ日時 2023-09-03 13:21:26
合計ジャッジ時間 7,758 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
21,892 KB
testcase_01 AC 65 ms
23,904 KB
testcase_02 AC 64 ms
21,916 KB
testcase_03 AC 65 ms
19,920 KB
testcase_04 AC 66 ms
21,748 KB
testcase_05 AC 66 ms
23,696 KB
testcase_06 AC 65 ms
21,764 KB
testcase_07 AC 65 ms
21,756 KB
testcase_08 AC 65 ms
23,868 KB
testcase_09 AC 64 ms
22,076 KB
testcase_10 AC 67 ms
23,824 KB
testcase_11 AC 65 ms
21,992 KB
testcase_12 AC 68 ms
23,796 KB
testcase_13 AC 66 ms
21,844 KB
testcase_14 AC 69 ms
23,988 KB
testcase_15 AC 68 ms
23,800 KB
testcase_16 AC 68 ms
21,820 KB
testcase_17 AC 118 ms
28,068 KB
testcase_18 AC 102 ms
28,232 KB
testcase_19 AC 74 ms
21,824 KB
testcase_20 AC 122 ms
32,684 KB
testcase_21 AC 170 ms
39,752 KB
testcase_22 AC 538 ms
49,880 KB
testcase_23 AC 542 ms
49,752 KB
testcase_24 AC 540 ms
49,632 KB
testcase_25 AC 539 ms
51,948 KB
testcase_26 AC 537 ms
51,804 KB
権限があれば一括ダウンロードができます

ソースコード

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(int n) => Enumerable.Repeat(0, n).Select(_ => NList).ToArray();
    static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m) = ((int)c[0], c[1]);
        var map = NArr(n);
        if (n == 1)
        {
            WriteLine(0);
            return;
        }
        var dp = new long[n][];
        for (var i = 0; i < dp.Length; ++i) dp[i] = Enumerable.Repeat(long.MaxValue / 2, m).ToArray();
        for (var j = 0; j < m; ++j)
        {
            dp[1][j] = map[0][j] + map[1][j];
        }
        for (var i = 1; i + 1 < n; ++i)
        {
            var fpos = 0;
            var fval = long.MaxValue;
            for (var j = 0; j < m; ++j)
            {
                if (dp[i][j] < fval)
                {
                    fpos = j;
                    fval = dp[i][j];
                }
            }
            for (var j = 0; j < m; ++j)
            {
                if (fpos == j)
                {
                    dp[i + 1][j] = Math.Min(dp[i + 1][j], dp[i][j] + map[i + 1][j]);
                }
                else
                {
                    dp[i + 1][j] = Math.Min(dp[i + 1][j], dp[i][j] + map[i + 1][j]);
                    dp[i + 1][j] = Math.Min(dp[i + 1][j], dp[i][fpos] + map[i][j] + map[i + 1][j]);
                }
            }
        }
        WriteLine(dp[n - 1].Min());
    }
}
0