結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
24,252 KB
testcase_01 AC 25 ms
24,252 KB
testcase_02 AC 26 ms
24,248 KB
testcase_03 AC 25 ms
24,252 KB
testcase_04 AC 25 ms
24,248 KB
testcase_05 AC 25 ms
24,248 KB
testcase_06 AC 26 ms
24,248 KB
testcase_07 AC 111 ms
32,596 KB
testcase_08 AC 136 ms
41,368 KB
testcase_09 WA -
testcase_10 AC 137 ms
41,368 KB
testcase_11 AC 136 ms
41,504 KB
testcase_12 AC 118 ms
32,632 KB
testcase_13 AC 116 ms
32,632 KB
testcase_14 AC 118 ms
32,632 KB
testcase_15 AC 117 ms
32,656 KB
testcase_16 AC 30 ms
24,580 KB
testcase_17 AC 27 ms
24,252 KB
testcase_18 AC 26 ms
24,252 KB
testcase_19 AC 26 ms
24,252 KB
testcase_20 AC 122 ms
32,620 KB
testcase_21 AC 123 ms
32,588 KB
testcase_22 AC 110 ms
32,596 KB
testcase_23 WA -
testcase_24 AC 113 ms
32,608 KB
testcase_25 AC 132 ms
40,012 KB
testcase_26 AC 135 ms
40,500 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 int[h, w];
        for (int i = 0; i < h; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            for (int j = 0; j < w; j++) map[i, j] = int.Parse(line[j]);
        }
        getAns(h, w, map);
    }
    static void getAns(int h, int w, int[,] 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