結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー 👑 kakel-sankakel-san
提出日時 2024-02-04 15:35:04
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 242 ms / 3,000 ms
コード長 1,786 bytes
コンパイル時間 7,041 ms
コンパイル使用メモリ 157,896 KB
実行使用メモリ 199,020 KB
最終ジャッジ日時 2024-02-04 15:35:17
合計ジャッジ時間 12,872 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
32,932 KB
testcase_01 AC 85 ms
32,932 KB
testcase_02 AC 83 ms
32,932 KB
testcase_03 AC 83 ms
32,932 KB
testcase_04 AC 83 ms
32,932 KB
testcase_05 AC 83 ms
32,932 KB
testcase_06 AC 84 ms
32,932 KB
testcase_07 AC 192 ms
48,036 KB
testcase_08 AC 137 ms
57,508 KB
testcase_09 AC 167 ms
61,988 KB
testcase_10 AC 167 ms
61,988 KB
testcase_11 AC 180 ms
60,068 KB
testcase_12 AC 157 ms
56,996 KB
testcase_13 AC 142 ms
47,524 KB
testcase_14 AC 146 ms
56,356 KB
testcase_15 AC 145 ms
56,356 KB
testcase_16 AC 114 ms
45,988 KB
testcase_17 AC 242 ms
50,084 KB
testcase_18 AC 114 ms
45,988 KB
testcase_19 AC 82 ms
32,932 KB
testcase_20 AC 83 ms
32,932 KB
testcase_21 AC 84 ms
32,932 KB
testcase_22 AC 170 ms
47,140 KB
testcase_23 AC 83 ms
32,932 KB
testcase_24 AC 127 ms
45,988 KB
testcase_25 AC 222 ms
199,020 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (99 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, x, y) = (c[0], c[1], c[2], c[3]);
        --x;
        --y;
        var map = NArr(h);
        var mx = new int[] { -1, 0, 1, 0 };
        var my = new int[] { 0, 1, 0, -1 };
        var val = (long)map[x][y];
        var added = new bool[h, w];
        added[x, y] = true;
        var q = new PriorityQueue<(int x, int y), int>();
        for (var d = 0; d < 4; ++d)
        {
            var nx = x + mx[d];
            var ny = y + my[d];
            if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
            if (added[nx, ny]) continue;
            q.Enqueue((nx, ny), map[nx][ny]);
            added[nx, ny] = true;
        }
        while (q.Count > 0)
        {
            var cur = q.Dequeue();
            if (val <= map[cur.x][cur.y])
            {
                WriteLine("No");
                return;
            }
            val += map[cur.x][cur.y];
            for (var d = 0; d < 4; ++d)
            {
                var nx = cur.x + mx[d];
                var ny = cur.y + my[d];
                if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
                if (added[nx, ny]) continue;
                q.Enqueue((nx, ny), map[nx][ny]);
                added[nx, ny] = true;
            }
        }
        WriteLine("Yes");
    }
}
0