結果
| 問題 | No.2695 Warp Zone |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-23 07:24:42 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 1,303 bytes |
| 記録 | |
| コンパイル時間 | 1,540 ms |
| コンパイル使用メモリ | 234,908 KB |
| 実行使用メモリ | 9,928 KB |
| 最終ジャッジ日時 | 2026-10-23 07:24:49 |
| 合計ジャッジ時間 | 3,504 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | AC * 2 WA * 23 |
ソースコード
#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(c == x && d == y) swap(a,c),swap(b,d);
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;
}