結果
| 問題 | No.3680 セグメント釣り |
| コンテスト | |
| ユーザー |
shira111
|
| 提出日時 | 2026-09-05 15:07:40 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,902 bytes |
| 記録 | |
| コンパイル時間 | 2,453 ms |
| コンパイル使用メモリ | 369,304 KB |
| 実行使用メモリ | 9,784 KB |
| 最終ジャッジ日時 | 2026-09-05 15:08:00 |
| 合計ジャッジ時間 | 6,788 ms |
|
ジャッジサーバーID (参考情報) |
judge5_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 4 WA * 2 RE * 7 |
ソースコード
#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> goal;
{
ll x = tx, y = ty;
int d = 0;
while(y <= 60) {
goal[P(x,y)] = d;
y++;
ll dx = 1LL << y;
ll rem = x % dx;
x -= rem;
d++;
}
}
//for(auto[p,d]:goal) { auto [x,y] = p; cerr<<'('<<x<<','<<y<<'='<<d<<") "; } cerr<<endl;
map<P,int> dist;
dist[P(sx,sy)] = 0;
queue<P> Q; Q.emplace(sx,sy);
int ans = 1e9;
while(!Q.empty()) {
auto[x,y] = Q.front(); Q.pop();
P pos = P(x,y);
if(dist[pos] > ans) continue;
if(goal.count(pos)) ans = min(ans, dist[pos] + goal[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);
}
//y軸は上方向だけ
{
dx *= 2;
ll rem = x % dx;
P nxt = P(x-rem, y+1);
if(dist.count(nxt)) continue;
dist[nxt] = dist[pos] + 1;
Q.push(nxt);
}
}
//for(auto[p,d]:dist) { auto [x,y] = p; cerr<<'('<<x<<','<<y<<'='<<d<<") "; } cerr<<endl;
return ans;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0); //入出力高速化
int T; cin>>T;
rep(i,T) cout<<solve()<<'\n';
}
shira111