結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー yansi819yansi819
提出日時 2024-04-15 12:58:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,310 bytes
コンパイル時間 5,527 ms
コンパイル使用メモリ 261,176 KB
実行使用メモリ 13,896 KB
最終ジャッジ日時 2024-04-15 12:58:44
合計ジャッジ時間 10,159 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,884 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 75 ms
7,552 KB
testcase_08 AC 120 ms
7,552 KB
testcase_09 AC 133 ms
7,424 KB
testcase_10 AC 133 ms
7,552 KB
testcase_11 AC 119 ms
7,552 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

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<ll>> vis(h, vector<ll>(w, 0));
  vis[0][0] = a[0][0];
  int dx[2] = {0, 1};
  int dy[2] = {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 < 2; i++) {
      ll AT = at, DT = dt;
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (0 > nx || nx >= h || 0 > ny || ny >= w) continue;
      //cout << nx << ' ' << ny << ' ' << AT << ' ' << DT << endl;
      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];
      }
      if (vis[nx][ny] >= AT) continue;
      vis[nx][ny] = AT;
      que.push({nx * w + ny, AT, DT});
    }
  }
  cout << (flag ? "Yes": "No") << endl;
  return 0;
}
0