結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー bluemeganebluemegane
提出日時 2022-05-21 10:15:31
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,935 bytes
コンパイル時間 995 ms
コンパイル使用メモリ 109,012 KB
実行使用メモリ 42,492 KB
最終ジャッジ日時 2023-10-20 15:47:59
合計ジャッジ時間 4,525 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
24,296 KB
testcase_01 AC 24 ms
24,296 KB
testcase_02 AC 23 ms
24,292 KB
testcase_03 AC 23 ms
24,292 KB
testcase_04 AC 25 ms
24,296 KB
testcase_05 AC 24 ms
24,296 KB
testcase_06 AC 24 ms
24,296 KB
testcase_07 AC 108 ms
33,584 KB
testcase_08 AC 130 ms
42,344 KB
testcase_09 WA -
testcase_10 AC 138 ms
42,356 KB
testcase_11 AC 126 ms
42,492 KB
testcase_12 AC 111 ms
33,620 KB
testcase_13 AC 114 ms
33,628 KB
testcase_14 AC 113 ms
33,620 KB
testcase_15 AC 108 ms
33,652 KB
testcase_16 AC 28 ms
24,616 KB
testcase_17 AC 24 ms
24,296 KB
testcase_18 AC 25 ms
24,296 KB
testcase_19 AC 24 ms
24,296 KB
testcase_20 AC 117 ms
33,620 KB
testcase_21 AC 115 ms
33,560 KB
testcase_22 AC 108 ms
33,584 KB
testcase_23 WA -
testcase_24 AC 109 ms
33,596 KB
testcase_25 AC 134 ms
40,976 KB
testcase_26 AC 137 ms
41,488 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]);
        }
        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]);
        }
        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