結果

問題 No.3680 セグメント釣り
コンテスト
ユーザー pengin_2000
提出日時 2026-09-05 13:57:58
言語 C
(gcc 15.3.0)
コンパイル:
gcc-15 -O2 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 405 ms / 2,000 ms
+ 186µs
コード長 689 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 166 ms
コンパイル使用メモリ 38,980 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-09-05 13:59:13
合計ジャッジ時間 6,139 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<stdio.h>
long long int f(long long int a, long long int b)
{
	while (a > 0 && b > 0)
	{
		b--;
		a >>= 1;
	}
	return a;
}
void solve()
{
	long long int sx, sy, tx, ty;
	scanf("%lld %lld %lld %lld", &sx, &sy, &tx, &ty);
	long long int ans, b;
	if (sy < ty)
	{
		b = ty - sy;
		sy = ty;
	}
	else
	{
		b = sy - ty;
		ty = sy;
	}
	if (sx > tx)
	{
		sx ^= tx;
		tx ^= sx;
		sx ^= tx;
	}
	ans = f(tx, ty) - f(sx, sy) + b;
	long long int i;
	for (i = sy; i < 100; i++)
		if (ans > f(tx, i) - f(sx, i) + b + 2 * (i - sy))
			ans = f(tx, i) - f(sx, i) + b + 2 * (i - sy);
	printf("%lld\n", ans);
	return;
}
int main()
{
	int t;
	scanf("%d", &t);
	for (; t > 0; t--)
		solve();
	return 0;
}
0