結果
| 問題 | No.1948 足し算するだけのパズルゲーム(1) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-05-20 23:02:30 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.89.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,491 bytes |
| 記録 | |
| コンパイル時間 | 3,613 ms |
| コンパイル使用メモリ | 136,708 KB |
| 最終ジャッジ日時 | 2025-01-29 11:27:52 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 TLE * 2 MLE * 6 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <tuple>
using namespace std;
int main()
{
int H, W;
cin >> H >> W;
vector<vector<int>> A(H, vector<int>(W));
for (int i = 0; i < H; i++)
{
for (int j = 0; j < W; j++)
cin >> A[i][j];
}
int dx[2] = {0, 1}, dy[2] = {1, 0};
vector<vector<vector<long long>>> f(2, vector<vector<long long>>(H, vector<long long>(W, -1)));
queue<tuple<int, int, int, long long>> q;
q.push({0, 0, 0, A[0][0]});
f[0][0][0] = A[0][0];
while (!q.empty())
{
auto [id, x, y, d] = q.front();
q.pop();
if (f[id][x][y] > d)
continue;
for (int i = 0; i < 2; i++)
{
int nx = x + dx[i], ny = y + dy[i];
if (0 <= nx && nx < H && 0 <= ny && ny < W)
{
if (d <= A[nx][ny] && id == 0 && (nx != H - 1 || ny != W - 1))
{
f[1][nx][ny] = max(f[1][nx][ny], d);
q.push({1, nx, ny, d});
}
else if (d > A[nx][ny])
{
f[id][nx][ny] = max(f[id][nx][ny], A[nx][ny] + d);
q.push({id, nx, ny, A[nx][ny] + d});
}
}
}
}
if (f[0][H - 1][W - 1] != -1 || f[1][H - 1][W - 1] != -1)
cout << "Yes" << endl;
else
cout << "No" << endl;
}