結果

問題 No.3680 セグメント釣り
コンテスト
ユーザー shira111
提出日時 2026-09-05 14:31:15
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,483 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,387 ms
コンパイル使用メモリ 367,580 KB
実行使用メモリ 221,364 KB
最終ジャッジ日時 2026-09-05 14:31:38
合計ジャッジ時間 10,859 ms
ジャッジサーバーID
(参考情報)
judge6_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other WA * 2 TLE * 1 -- * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define all(c) c.begin(), c.end()
using namespace std;
typedef long long ll; typedef long double ld;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>;  using vvl = vector<vl>;

using P = pair<ll,ll>;

ll solve() {
	//答えはmax120程度
	//BFS書けないか?
	ll sx,sy,tx,ty; cin>>sx>>sy>>tx>>ty;

	if(sy > 60 || ty > 60) return abs(sy - ty); //y>60なら左端マスがxの全範囲をカバー
	
	//x座標は左端に寄せる
	{
		ll dx = 1LL << sy;
		ll rem = sx % dx;
		sx -= rem;
	}
	{
		ll dx = 1LL << ty;
		ll rem = tx % dx;
		tx -= rem;
	}

	map<P,int> dist;
	dist[P(sx,sy)] = 0;
	queue<P> Q; Q.emplace(sx,sy);

	while(!Q.empty()) {
		auto[x,y] = Q.front(); Q.pop();
		P pos = P(x,y);
		if(x == tx && y == ty) return dist[pos];

		ll dx = 1LL << y;

		if(x < tx) {
			P nxt = P(x+dx, y);
			if(dist.count(nxt)) continue;
			dist[nxt] = dist[pos] + 1;
			Q.push(nxt);
		}
		if(tx < x) {
			P nxt = P(x-dx, y);
			if(dist.count(nxt)) continue;
			dist[nxt] = dist[pos] + 1;
			Q.push(nxt);
		}
		if(y < ty) {
			P nxt = P(x, y+1);
			if(dist.count(nxt)) continue;
			dist[nxt] = dist[pos] + 1;
			Q.push(nxt);
		}
		if(ty < y) {
			P nxt = P(x, y-1);
			if(dist.count(nxt)) continue;
			dist[nxt] = dist[pos] + 1;
			Q.push(nxt);
		}
	}

	return 0;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0); //入出力高速化

	int T; cin>>T;
	rep(i,T) cout<<solve()<<'\n';
}
0