結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー 👑 kakel-sankakel-san
提出日時 2024-02-04 15:21:47
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 1,757 bytes
コンパイル時間 6,948 ms
コンパイル使用メモリ 157,548 KB
実行使用メモリ 204,632 KB
最終ジャッジ日時 2024-02-04 15:21:59
合計ジャッジ時間 11,613 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
32,932 KB
testcase_01 AC 77 ms
32,932 KB
testcase_02 AC 76 ms
32,932 KB
testcase_03 AC 77 ms
32,932 KB
testcase_04 AC 76 ms
32,932 KB
testcase_05 AC 76 ms
32,932 KB
testcase_06 AC 76 ms
32,932 KB
testcase_07 AC 120 ms
51,748 KB
testcase_08 AC 140 ms
57,892 KB
testcase_09 AC 163 ms
57,892 KB
testcase_10 AC 142 ms
58,020 KB
testcase_11 AC 138 ms
58,020 KB
testcase_12 AC 135 ms
61,048 KB
testcase_13 AC 135 ms
61,064 KB
testcase_14 AC 136 ms
61,044 KB
testcase_15 AC 134 ms
61,024 KB
testcase_16 AC 79 ms
33,188 KB
testcase_17 AC 77 ms
33,188 KB
testcase_18 AC 84 ms
32,932 KB
testcase_19 AC 76 ms
32,932 KB
testcase_20 AC 137 ms
61,088 KB
testcase_21 AC 131 ms
56,484 KB
testcase_22 AC 123 ms
52,900 KB
testcase_23 AC 122 ms
52,900 KB
testcase_24 AC 123 ms
52,772 KB
testcase_25 AC 140 ms
58,020 KB
testcase_26 AC 147 ms
204,632 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (91 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;
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 (h, w) = (c[0], c[1]);
        var map = NArr(h);
        var dp = new long[2][][];
        for (var i = 0; i < 2; ++i)
        {
            dp[i] = new long[h][];
            for (var j = 0; j < h; ++j) dp[i][j] = Enumerable.Repeat(long.MinValue, w).ToArray();
        }
        dp[0][0][0] = map[0][0];
        for (var i = 0; i < h; ++i) for (var j = 0; j < w; ++j)
        {
            if (i + 1 < h)
            {
                if (dp[0][i][j] > map[i + 1][j]) dp[0][i + 1][j] = Math.Max(dp[0][i + 1][j], dp[0][i][j] + map[i + 1][j]);
                else dp[1][i + 1][j] = Math.Max(dp[1][i + 1][j], dp[0][i][j]);
                if (dp[1][i][j] > map[i + 1][j]) dp[1][i + 1][j] = Math.Max(dp[1][i + 1][j], dp[1][i][j] + map[i + 1][j]);
            }
            if (j + 1 < w)
            {
                if (dp[0][i][j] > map[i][j + 1]) dp[0][i][j + 1] = Math.Max(dp[0][i][j + 1], dp[0][i][j] + map[i][j + 1]);
                else dp[1][i][j + 1] = Math.Max(dp[1][i][j + 1], dp[0][i][j]);
                if (dp[1][i][j] > map[i][j + 1]) dp[1][i][j + 1] = Math.Max(dp[1][i][j + 1], dp[1][i][j] + map[i][j + 1]);
            }
        }
        WriteLine(Math.Max(dp[0][h - 1][w - 1], dp[1][h - 1][w - 1]) > map[h - 1][w - 1] ? "Yes" : "No");
    }
}
0