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