結果
問題 | No.2695 Warp Zone |
ユーザー |
|
提出日時 | 2024-03-28 15:10:39 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,306 bytes |
コンパイル時間 | 5,665 ms |
コンパイル使用メモリ | 313,328 KB |
実行使用メモリ | 35,052 KB |
最終ジャッジ日時 | 2024-09-30 14:44:47 |
合計ジャッジ時間 | 5,744 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 WA * 1 |
ソースコード
#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];int M = 2*N+2;ll G[M][M] = {};rep(i,M) rep(j,M) G[i][j] = 1e18;rep(i,2*N) rep(j,2*N) if(i!=j){int a = (i&1?2:0);int b = (j&1?2:0);G[i][j] = abs(A[i/2][a]-A[j/2][b]) + abs(A[i/2][a+1]-A[j/2][b+1]);}rep(i,N) G[2*i][2*i+1] = 1;rep(i,2*N){int a = (i&1?2:0);G[2*N][i] = G[i][2*N] = A[i/2][a] + A[i/2][a+1] - 2;G[2*N+1][i] = G[i][2*N+1] = H-A[i/2][a] + W-A[i/2][a+1];}G[2*N][2*N+1] = H+W-1;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;rep(nv,2*N+2) if(nv!=v && G[v][nv]<1e18){if(chmin(dist[nv], dist[v]+G[v][nv])) q.push({dist[nv], nv});}}//rep(i,M) cout << dist[i] << endl;cout << dist[2*N+1] << endl;}