結果
| 問題 |
No.1948 足し算するだけのパズルゲーム(1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-15 11:37:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,259 bytes |
| コンパイル時間 | 4,134 ms |
| コンパイル使用メモリ | 260,280 KB |
| 最終ジャッジ日時 | 2025-02-21 02:08:22 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 WA * 11 |
ソースコード
#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;
}