結果

問題 No.2213 Neq Move
ユーザー ttkkggwwttkkggww
提出日時 2023-02-10 23:22:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 679 bytes
コンパイル時間 4,772 ms
コンパイル使用メモリ 259,944 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 00:25:23
合計ジャッジ時間 4,781 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
ll A,B,C,D;

void solve(){
	ll ans = C+D+2;
	if(A==1||B==1)ans = C+D+3;
	for(int isA = 0;isA<2;isA++){
		for(int isB = 0;isB<2;isB++){
			if(isA==0&&isB==0){
				if((A<B)==(C<D)&&A<=C&&B<=D){
					ans = min(ans,C-A+D-B);
				}
			}else if(isA==0&&isB==1){
				if(C>D&&A<=C){
					ans = min(ans,C-A+D+1);
				}
			}else if(isA==1&&isB==0){
				if(C<D&&B<=D){
					ans = min(ans,D-B+C+1);
				}
			}
		}
	}
	cout<<ans<<endl;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while(t--){
		cin >> A >> B >> C >> D;
		solve();
	}
}
0