結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー RVindicatioRVindicatio
提出日時 2022-05-20 22:08:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,250 bytes
コンパイル時間 3,973 ms
コンパイル使用メモリ 230,696 KB
実行使用メモリ 814,708 KB
最終ジャッジ日時 2023-10-20 12:49:08
合計ジャッジ時間 7,934 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 32 ms
5,360 KB
testcase_09 MLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
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 #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

using ll = long long;
const int INF = 1e9;
const ll inf = 1LL<<60;

void solve() {
  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<vector<ll>> q;
  q.push({0, 0, a[0][0], 0});
  while (q.size()) {
    auto now = q.front(); q.pop();
    int i = now[0], j = now[1];
    if (i == h-1 && j == w-1) {
      cout << "Yes" << '\n';
      return;
    }
    ll lv = now[2], state = now[3];
    if (i + 1 < h) {
      if (lv > a[i+1][j]) {
        q.push({i+1, j, lv+a[i+1][j], state});
      } else {
        if (state == 1) continue;
        if (i+1 == h-1 && j == w-1) continue;
        q.push({i+1, j, lv, state+1});
      }
    }
    if (j+1 < w) {
      if (lv > a[i][j+1]) {
        q.push({i, j+1, lv+a[i][j+1], state});
      } else {
        if (state == 1) continue;
        if (i == h-1 && j+1 == w-1) continue;
        q.push({i, j+1, lv, state+1});
      }
    }
  }
  cout << "No" << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  // int t; cin >> t;
  /*while (t--)*/ solve();
}
0