結果

問題 No.2695 Warp Zone
コンテスト
ユーザー GOTKAKO
提出日時 2026-10-23 07:25:13
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,249 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,668 ms
コンパイル使用メモリ 235,056 KB
実行使用メモリ 9,920 KB
最終ジャッジ日時 2026-10-23 07:25:18
合計ジャッジ時間 4,342 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 2 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    long long H,W; cin >> H >> W;
    int N; cin >> N;
    vector<tuple<int,int,int,int>> edge(N);
    vector<pair<int,int>> XY = {{0,0},{H-1,W-1}};
    for(auto &[a,b,c,d] : edge){
        cin >> a >> b >> c >> d,a--,b--,c--,d--;
        XY.push_back({a,b}),XY.push_back({c,d});
    }    
    sort(XY.begin(),XY.end());
    int n = XY.size();
    vector<long long> dist(n,1e18);
    dist.at(0) = 0;
    priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<>> Q;
    Q.push({0,0});
    while(Q.size()){
        auto [d,pos] = Q.top(); Q.pop();
        if(dist.at(pos) != d) continue;
        auto [x,y] = XY.at(pos);
        for(int to=0; to<n; to++){
            auto [x2,y2] = XY.at(to);
            long long now = d+abs(x-x2)+abs(y-y2);
            if(dist.at(to) > now) dist.at(to) = now,Q.push({now,to});
        }
        for(auto [a,b,c,d] : edge){
            if(a == x && b == y){
                int to = lower_bound(XY.begin(),XY.end(),pair{c,d})-XY.begin();
                if(dist.at(to) > d+1) Q.push({d+1,to}),dist.at(to) = d+1;
            }
        }
    }
    cout << dist.at(n-1) << endl;
}
0