結果

問題 No.2695 Warp Zone
ユーザー nwonwo
提出日時 2024-03-28 15:07:50
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,283 bytes
コンパイル時間 5,921 ms
コンパイル使用メモリ 314,148 KB
実行使用メモリ 35,120 KB
最終ジャッジ日時 2024-03-28 15:07:57
合計ジャッジ時間 7,335 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 38 ms
35,120 KB
testcase_04 AC 37 ms
33,884 KB
testcase_05 AC 37 ms
33,884 KB
testcase_06 AC 36 ms
34,808 KB
testcase_07 AC 37 ms
35,120 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 15 ms
13,884 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 6 ms
6,676 KB
testcase_12 AC 19 ms
18,380 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 24 ms
22,720 KB
testcase_15 AC 13 ms
12,548 KB
testcase_16 AC 6 ms
6,676 KB
testcase_17 AC 9 ms
8,720 KB
testcase_18 AC 30 ms
27,464 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 26 ms
24,844 KB
testcase_21 AC 24 ms
22,332 KB
testcase_22 AC 13 ms
11,520 KB
testcase_23 AC 19 ms
18,252 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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];
	}

	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;
}
0