結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー yansi819yansi819
提出日時 2024-04-15 11:37:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,259 bytes
コンパイル時間 5,735 ms
コンパイル使用メモリ 263,984 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 11:37:28
合計ジャッジ時間 9,120 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 WA -
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 69 ms
6,940 KB
testcase_08 AC 120 ms
6,940 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 97 ms
6,944 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 83 ms
6,944 KB
testcase_16 WA -
testcase_17 AC 2 ms
6,940 KB
testcase_18 WA -
testcase_19 AC 3 ms
6,940 KB
testcase_20 AC 93 ms
6,944 KB
testcase_21 WA -
testcase_22 AC 68 ms
6,944 KB
testcase_23 AC 67 ms
6,940 KB
testcase_24 AC 78 ms
6,940 KB
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;

int main() {
  int h, w; cin >> h >> w;
  vector<vector<ll>> a(h, vector<ll>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) cin >> a[i][j];
  }
  queue<tuple<ll, ll, ll>> que;
  que.push({0, a[0][0], 0});
  vector<vector<bool>> vis(h, vector<bool>(w, false));
  vis[0][0] = true;
  int dx[4] = {-1, 0, 0, 1};
  int dy[4] = {0, -1, 1, 0};
  bool flag = false;
  while (!que.empty()) {
    auto &[id, at, dt] = que.front(); que.pop();
    int x = id / w;
    int y = id % w;
    if (x == h - 1 && y == w - 1) {
      flag = true;
      break;
    }
    for (int i = 0; i < 4; i++) {
      int AT = at, DT = dt;
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (0 > nx || nx >= h || 0 > ny || ny >= w) continue;
      if (vis[nx][ny]) continue;
      vis[nx][ny] = true;
      if (a[nx][ny] >= AT) {
        if (nx == h - 1 && ny == w - 1) continue;
        else if (DT > 0) continue;
        else DT += 1;
      } else {
        AT += a[nx][ny];
      }
      que.push({nx * w + ny, AT, DT});
    }
  }
  cout << (flag ? "Yes": "No") << endl;
  return 0;
}
0