結果
問題 | No.1948 足し算するだけのパズルゲーム(1) |
ユーザー |
|
提出日時 | 2022-06-17 22:13:38 |
言語 | C# (.NET 8.0.404) |
結果 |
AC
|
実行時間 | 137 ms / 2,000 ms |
コード長 | 2,578 bytes |
コンパイル時間 | 9,768 ms |
コンパイル使用メモリ | 166,688 KB |
実行使用メモリ | 210,104 KB |
最終ジャッジ日時 | 2024-10-09 08:15:02 |
合計ジャッジ時間 | 14,215 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (98 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 System.Collections; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; //using static CompLib.CompLib; //using DataStructure; namespace atcoder { class Program { const int intMax = 1000000000; const long longMax = 2000000000000000000; static void Main(string[] args) { var HW = Console.ReadLine().Trim().Split().Select(int.Parse).ToArray(); int H = HW[0]; int W = HW[1]; var grid = new long[H, W]; for (int i = 0; i < H; i++) { var read = Console.ReadLine().Trim().Split().Select(long.Parse).ToArray(); for (int j = 0; j < W; j++) { grid[i, j] = read[j]; } } var defeat = new bool[H, W, 2]; var move = new (int, int)[2] { (0, 1), (1, 0) }; var q = new Queue<(int, int, long, int)>(); q.Enqueue((0, 0, grid[0, 0], 0)); var ok = false; while (q.Count > 0) { var now = q.Dequeue(); if (now.Item1 == H - 1 && now.Item2 == W - 1 && now.Item3 > grid[H - 1, W - 1]) { ok = true; break; } foreach (var i in move) { int ny = now.Item1 + i.Item1; int nx = now.Item2 + i.Item2; if (ny < H && ny >= 0 && nx >= 0 && nx < W) { if (now.Item4 == 0 && now.Item3 <= grid[ny, nx] && !defeat[ny, nx, 1]) { defeat[ny, nx, 1] = true; q.Enqueue((ny, nx, now.Item3, 1)); } else if (now.Item4 == 0 && now.Item3 > grid[ny, nx] && !defeat[ny, nx, 0]) { defeat[ny, nx, 0] = true; q.Enqueue((ny, nx, now.Item3 + grid[ny, nx], 0)); } else if (now.Item4 == 1 && now.Item3 > grid[ny, nx] && !defeat[ny, nx, 1]) { defeat[ny, nx, 1] = true; q.Enqueue((ny, nx, now.Item3 + grid[ny, nx], 1)); } } } } if (ok) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }