結果

問題 No.2695 Warp Zone
ユーザー nwonwo
提出日時 2024-03-28 14:47:13
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,576 bytes
コンパイル時間 5,726 ms
コンパイル使用メモリ 313,652 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-28 14:47:20
合計ジャッジ時間 7,372 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
6,548 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
6,548 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
6,548 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
6,548 KB
testcase_25 AC 2 ms
6,548 KB
testcase_26 AC 2 ms
6,548 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];

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