結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー bluemeganebluemegane
提出日時 2022-05-24 07:05:51
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 2,288 bytes
コンパイル時間 4,006 ms
コンパイル使用メモリ 108,980 KB
実行使用メモリ 42,528 KB
最終ジャッジ日時 2023-10-20 17:52:17
合計ジャッジ時間 8,056 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
24,328 KB
testcase_01 AC 23 ms
24,328 KB
testcase_02 AC 24 ms
24,324 KB
testcase_03 AC 24 ms
24,324 KB
testcase_04 AC 22 ms
24,328 KB
testcase_05 AC 22 ms
24,328 KB
testcase_06 AC 23 ms
24,328 KB
testcase_07 AC 106 ms
33,620 KB
testcase_08 AC 124 ms
42,380 KB
testcase_09 AC 133 ms
42,392 KB
testcase_10 AC 126 ms
42,392 KB
testcase_11 AC 127 ms
42,528 KB
testcase_12 AC 107 ms
33,656 KB
testcase_13 AC 112 ms
33,664 KB
testcase_14 AC 114 ms
33,656 KB
testcase_15 AC 110 ms
33,688 KB
testcase_16 AC 27 ms
24,668 KB
testcase_17 AC 22 ms
24,328 KB
testcase_18 AC 23 ms
24,328 KB
testcase_19 AC 22 ms
24,328 KB
testcase_20 AC 119 ms
33,656 KB
testcase_21 AC 120 ms
33,596 KB
testcase_22 AC 102 ms
33,620 KB
testcase_23 AC 98 ms
33,632 KB
testcase_24 AC 107 ms
33,632 KB
testcase_25 AC 125 ms
41,012 KB
testcase_26 AC 129 ms
41,524 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var h = int.Parse(line[0]);
        var w = int.Parse(line[1]);
        var map = new long[h, w];
        for (int i = 0; i < h; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            for (int j = 0; j < w; j++) map[i, j] = long.Parse(line[j]);
        }
        getAns(h, w, map);
    }
    static void getAns(int h, int w, long[,] map)
    {
        var dp = new long[h, w, 2];
        dp[0, 0, 0] = map[0, 0];
        for (int i = 1; i < w; i++)
        {
            if (dp[0, i - 1, 0] > map[0, i])
            {
                var t = dp[0, i - 1, 0] + map[0, i];
                dp[0, i, 0] = Max(dp[0, i, 0], t);
            }
            else dp[0, i, 1] = Max(dp[0, i, 1], dp[0, i - 1, 0]);
            if (dp[0, i - 1, 1] > map[0, i])
            {
                var t = dp[0, i - 1, 1] + map[0, i];
                dp[0, i, 1] = Max(dp[0, i,1], t);
            }
        }
        for (int i = 1; i < h; i++)
        {
            if (dp[i - 1, 0, 0] > map[i, 0])
            {
                var t = dp[i - 1, 0, 0] + map[i, 0];
                dp[i, 0, 0] = Max(dp[i, 0, 0], t);
            }
            else dp[i, 0, 1] = Max(dp[i, 0, 1], dp[i - 1, 0, 0]);
            if (dp[i - 1, 0, 1] > map[i, 0])
            {
                var t = dp[i - 1, 0, 1] + map[i, 0];
                dp[i, 0, 1] = Max(dp[i, 0, 1], t);
            }
        }
        for (int i = 1; i < w; i++)
        {
            for (int j = 1; j < h; j++)
            {
                var abmax = Max(dp[j - 1, i, 0], dp[j, i - 1, 0]);
                if (abmax > map[j, i]) dp[j, i, 0] = Max(dp[j, i, 0], abmax + map[j, i]);
                else
                {
                    if (!(j == h - 1 && i == w - 1))
                        dp[j, i, 1] = Max(dp[j, i, 1], abmax);
                }
                var abmax2 = Max(dp[j - 1, i, 1], dp[j, i - 1, 1]);
                if (abmax2 > map[j, i]) dp[j, i, 1] = Max(dp[j, i, 1], abmax2 + map[j, i]);
            }
        }
        var f = dp[h - 1, w - 1, 0] > 0 | dp[h - 1, w - 1, 1] > 0;
        Console.WriteLine(f ? "Yes" : "No");
    }
}
0