結果

問題 No.2695 Warp Zone
ユーザー GGanariGGanari
提出日時 2024-03-22 22:03:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,723 bytes
コンパイル時間 3,632 ms
コンパイル使用メモリ 233,940 KB
実行使用メモリ 19,712 KB
最終ジャッジ日時 2024-03-22 22:03:27
合計ジャッジ時間 4,876 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 30 ms
19,712 KB
testcase_04 AC 26 ms
19,328 KB
testcase_05 AC 25 ms
19,328 KB
testcase_06 AC 26 ms
19,584 KB
testcase_07 AC 31 ms
19,712 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 14 ms
10,880 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 7 ms
6,676 KB
testcase_12 AC 18 ms
13,440 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 22 ms
16,000 KB
testcase_15 AC 13 ms
10,112 KB
testcase_16 AC 6 ms
6,676 KB
testcase_17 AC 9 ms
6,676 KB
testcase_18 AC 23 ms
17,536 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 23 ms
16,640 KB
testcase_21 AC 22 ms
15,872 KB
testcase_22 AC 10 ms
7,552 KB
testcase_23 AC 18 ms
13,440 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 #

#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
#define INF 1000000001LL
#define LNF 1000000000000000001LL
#define MOD 998244353LL
#define MAX 2001
#define long long long
#define all(x) x.begin(),x.end()
using namespace std;

vector<pair<long,long>> graph[1005];

void dijkstra(int x, vector<long> &vis, vector<pair<long,long>> graph[])
{
    priority_queue<pair<long,long>, vector<pair<long,long>>, greater<pair<long,long>>> pq;
	for(int i = 0; i<vis.size(); i++)
	{
		vis[i] = LNF;
	}
	vis[x] = 0;

	pq.push(make_pair(0,x));
	while(!pq.empty())
	{
		long a = pq.top().first;
		long b = pq.top().second;
		pq.pop();
        if(vis[b] < a)
            continue;
		for(int i = 0; i<graph[b].size(); i++)
		{
			long ai = graph[b][i].first;
			long bi = graph[b][i].second;

			if(bi+a < vis[ai])
			{
				vis[ai] = bi+a;
				pq.push(make_pair(vis[ai],ai));
			}
		}
	}
}
struct point
{
    long x1,y1,x2,y2;
};

long cal(point a, point b)
{
    return abs(a.x2-b.x1)+abs(a.y2-b.y1);
}
int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);

    long n,m,k;
    cin >> n >> m >> k;

    vector<point> arr;
    arr.push_back({1,1,1,1});

    for(int i = 0; i<k; i++)
    {
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        arr.push_back({a,b,c,d});
    }
    arr.push_back({n,m,n,m});

    n = arr.size();
    for(int i = 0; i<n; i++)
    {
        for(int j = 0; j<n; j++)
        {
            if(i == j)
                continue;
            graph[i].push_back({j,cal(arr[i],arr[j])+1});
        }
    }
    vector<long> vis(n);
    dijkstra(0,vis,graph);
    cout << vis[n-1]-1 << endl;
    return 0;
}
0