結果

問題 No.424 立体迷路
ユーザー peroonperoon
提出日時 2019-05-13 17:59:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,470 bytes
コンパイル時間 1,573 ms
コンパイル使用メモリ 171,744 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-18 17:06:54
合計ジャッジ時間 2,698 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,504 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:107:36: 警告: ‘nh’ may be used uninitialized [-Wmaybe-uninitialized]
  107 |                 if(h==height2 && nh<h){
      |                                  ~~^~
main.cpp:90:16: 備考: ‘nh’ はここで定義されています
   90 |             ll nh;
      |                ^~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

struct Point{
    ll x;
    ll y;
    Point(ll x, ll y): x(x), y(y) {}
};

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

ll d[100][100];

ll H, W;
bool in_range(ll x, ll y){
    if(0<=x && x<W && 0<=y && y<H){
        return true;
    }else{
        return false;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    cin >> H >> W;

    ll sx, sy, gx, gy;

    // cin >> sx >> sy >> gx >> gy;
    cin >> sy >> sx >> gy >> gx;
    
    sx--;
    sy--;
    gx--;
    gy--;

    vector<string> G(H);
    FOR(i, 0, H){
        cin >> G.at(i);
    }

    FOR(i, 0, 100){
        FOR(j, 0, 100){
            d[i][j] = inf;
        }
    }

    queue<Point> que;
    
    que.push(Point(sx, sy));
    d[sy][sx] = 0;

    while(!que.empty()){
        auto p = que.front();
        que.pop();
        ll h = G[p.y][p.x] - '0';
        
        FOR(i, 0, 4){
            ll nx = p.x + dx[i];
            ll ny = p.y + dy[i];
            
            ll nh;
            if(in_range(nx, ny) && d[ny][nx]==inf){
                nh = G[ny][nx] - '0';
                ll diff = abs(nh - h);
                if(diff<=1){
                    // 行ける
                    que.push(Point(nx, ny));
                    d[ny][nx] = d[p.y][p.x] + 1;
                }
            }

            // はしご
            nx += dx[i];
            ny += dy[i];

            if(in_range(nx, ny) && d[ny][nx]==inf){
                ll height2 = G[ny][nx] - '0';
                if(h==height2 && nh<h){
                    // わたせる
                    que.push(Point(nx, ny));
                    d[ny][nx] = d[p.y][p.x] + 1;
                }
            }
        }
    }

    if(d[gy][gx]==inf){
        p_no();
    }else{
        p_yes();
    }
    
    return 0;
}
0