結果
問題 | No.1949 足し算するだけのパズルゲーム(2) |
ユーザー |
|
提出日時 | 2024-02-04 15:35:04 |
言語 | C# (.NET 8.0.404) |
結果 |
AC
|
実行時間 | 335 ms / 3,000 ms |
コード長 | 1,786 bytes |
コンパイル時間 | 7,755 ms |
コンパイル使用メモリ | 168,288 KB |
実行使用メモリ | 204,148 KB |
最終ジャッジ日時 | 2024-09-28 11:18:33 |
合計ジャッジ時間 | 12,070 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (94 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
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"); } }