結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー nawawannawawan
提出日時 2022-05-20 23:02:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,491 bytes
コンパイル時間 1,121 ms
コンパイル使用メモリ 102,776 KB
実行使用メモリ 814,956 KB
最終ジャッジ日時 2023-10-20 13:56:00
合計ジャッジ時間 4,058 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 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 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 MLE -
testcase_08 -- -
testcase_09 -- -
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 #

#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;
}
0