結果

問題 No.2213 Neq Move
ユーザー 沙耶花沙耶花
提出日時 2023-02-10 22:45:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,449 bytes
コンパイル時間 4,870 ms
コンパイル使用メモリ 267,416 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-21 23:53:29
合計ジャッジ時間 4,732 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 7 ms
4,384 KB
testcase_02 AC 7 ms
4,380 KB
testcase_03 AC 8 ms
4,376 KB
testcase_04 AC 7 ms
4,376 KB
testcase_05 AC 7 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001


int main(){
	
	int _t;
	cin>>_t;
	
	rep(_,_t){
		long long a,b,c,d;
		cin>>a>>b>>c>>d;
		
		vector<long long> va = {0,1,a,c,2},vb = {0,1,b,d,2};
		int s = va.size();
		vector dis(s,vector<long long>(s,Inf64));
		dis[2][2] = 0;
		priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>> Q;
		Q.emplace(0,2*s + 2);
		while(Q.size()>0){
			long long D = Q.top().first;
			int x = Q.top().second/s;
			int y = Q.top().second%s;
			Q.pop();
			if(dis[x][y]!=D)continue;
			rep(i,s){
				rep(j,s){
					if(va[i]==vb[j])continue;
					if(i==x){
						long long DD = D;
						if(j==0)DD++;
						else{
							if(vb[y] <= va[x] && va[x] <= vb[j])continue;
							if(vb[y]>vb[j])continue;
							DD += abs(vb[y] - vb[j]);
						}
						if(dis[i][j]>DD){
							dis[i][j] = DD;
							Q.emplace(DD,i*s+j);
						}
					}
					if(j==y){
						long long DD = D;
						if(i==0)DD++;
						else{
							if(va[x] <= vb[y] && vb[y] <= va[i])continue;
							if(va[x]>va[i])continue;
							DD += abs(va[x] - va[i]);
						}
						if(dis[i][j]>DD){
							dis[i][j] = DD;
							Q.emplace(DD,i*s+j);
						}
					}
				}
			}
			
		}
		cout<<dis[3][3]<<endl;
		
	}
	
	return 0;
}
0