結果

問題 No.20 砂漠のオアシス
ユーザー Kutimoti_TKutimoti_T
提出日時 2017-12-18 17:39:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 530 ms / 5,000 ms
コード長 2,375 bytes
コンパイル時間 552 ms
コンパイル使用メモリ 69,048 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 05:44:06
合計ジャッジ時間 2,770 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 530 ms
4,376 KB
testcase_06 AC 74 ms
4,376 KB
testcase_07 AC 86 ms
4,376 KB
testcase_08 AC 158 ms
4,376 KB
testcase_09 AC 87 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 7 ms
4,376 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 16 ms
4,376 KB
testcase_17 AC 9 ms
4,376 KB
testcase_18 AC 17 ms
4,376 KB
testcase_19 AC 18 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define FOR(i, s, e) for (int i = (s); i <= (e); i++)

#define INF 1000000;

int N, V;

int Ox, Oy;

int L[210][210];

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int dp[210][210];
int dp2[210][210];

int main()
{
    FOR(i, 0, 209)
    {
        FOR(j, 0, 209)
        {
            dp[i][j] = INF;
            dp2[i][j] = INF;
        }
    }
    cin >> N >> V;
    cin >> Ox >> Oy;
    FOR(i, 1, N)
    {
        FOR(j, 1, N)
        {
            cin >> L[j][i];
        }
    }
    dp[1][1] = 0;

    while (true)
    {
        bool update = false;

        FOR(i, 1, N)
        {
            FOR(j, 1, N)
            {
                FOR(k, 0, 3)
                {
                    int x = i + dx[k];
                    int y = j + dy[k];

                    if (1 <= x && x <= N && 1 <= y && y <= N)
                    {
                        if (dp[x][y] > dp[i][j] + L[x][y])
                        {
                            dp[x][y] = dp[i][j] + L[x][y];
                            update = true;
                        }
                    }
                }
            }
        }
        if (update == false)
            break;
    }

    if (Ox != 0 && Oy != 0)
    {
        dp2[Ox][Oy] = 0;
        while (true)
        {
            bool update = false;
            FOR(i, 1, N)
            {
                FOR(j, 1, N)
                {
                    FOR(k, 0, 3)
                    {
                        int x = i + dx[k];
                        int y = j + dy[k];

                        if (1 <= x && x <= N && 1 <= y && y <= N)
                        {
                            if (dp2[x][y] > dp2[i][j] + L[x][y])
                            {
                                dp2[x][y] = dp2[i][j] + L[x][y];
                                update = true;
                            }
                        }
                    }
                }
            }
            if(update == false) break;
        }
    }

    if (dp[N][N] < V)
        cout << "YES" << endl;
    else if (Ox != 0 && Oy != 0 && ((V - dp[Ox][Oy]) * 2 - dp2[N][N] > 0))
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}
0