結果
問題 | No.2695 Warp Zone |
ユーザー |
|
提出日時 | 2024-03-28 14:47:13 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,576 bytes |
コンパイル時間 | 5,314 ms |
コンパイル使用メモリ | 312,840 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-09-30 14:44:33 |
合計ジャッジ時間 | 6,652 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 3 RE * 9 WA * 12 |
ソースコード
#include<bits/stdc++.h>using namespace std;#include<atcoder/all>using namespace atcoder;#define rep(i,n) for (int i = 0; i < (n); ++i)using ld = long double;using ll = long long;template<class T> bool chmax(T &a, T b){if(a<b){a = b;return true;}return false;}template<class T> bool chmin(T &a, T b){if(a>b){a = b;return true;}return false;}int H, W, N, A[1<<10][4];using P = pair<ll,ll>;int main(){cin >> H >> W >> N;rep(i,N) rep(j,4) cin >> A[i][j];priority_queue<P, vector<P>, greater<P>> q;q.push({0,2*N});vector<ll> dist(2*N+2, 1e18);dist[2*N] = 0;while(!q.empty()){auto [c,v] = q.top();q.pop();if(dist[v]<c) continue;int s = 0;if(0<=v && v<2*N && v&1) s = 2;rep(i,N) if(i!=v){ll d1 = 0;if(v<2*N) d1 = abs(A[i][0]-A[v/2][s]) + abs(A[i][1]-A[v][s+1]);else{if(v==2*N) d1 = A[i][0]+A[i][1]-2;if(v==2*N+1) d1 = H-A[i][0] + W-A[i][1];}if(chmin(dist[2*i], dist[v]+d1)) q.push({dist[2*i], 2*i});ll d2 = 0;if(v<2*N) d2 = abs(A[i][2]-A[v/2][s]) + abs(A[i][3]-A[v/2][s+1]);else{if(v==2*N) d2 = A[i][2]+A[i][3]-2;if(v==2*N+1) d2 = H-A[i][2] + W-A[i][3];}if(chmin(dist[2*i+1], dist[v]+d2)) q.push({dist[2*i+1], 2*i+1});}if(0<=v && v<2*N && s==0){if(chmin(dist[v+1], dist[v]+1)) q.push({dist[v+1], v+1});}}ll ans = 1e18;rep(i,2*N){int s = 0;if(i&1) s = 2;//cout << i/2 << "," << s/2 << " : " << dist[i] << endl;ll d = H-A[i/2][s]+W-A[i/2][s+1]+dist[i];chmin(ans, d);}cout << ans << endl;}