結果

問題 No.3679 なんかでっかい虫リターンズ
コンテスト
ユーザー sorachandu
提出日時 2026-09-05 14:04:10
言語 C++23
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
+ 699µs
コード長 1,261 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,020 ms
コンパイル使用メモリ 345,388 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-09-05 14:05:48
合計ジャッジ時間 3,783 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(nullptr)->ios::sync_with_stdio(false);
    int H,W,A,B;
    cin>>H>>W>>A>>B;
    int R1,C1,R2,C2;
    cin>>R1>>C1>>R2>>C2;
    int P,Q;
    cin>>P>>Q;
    A--,B--,R1--,C1--,R2--,C2--,P--,Q--;
    // 場外判定
    auto outof = [&](unsigned int y, unsigned int x){
        return (y >= H || x >= W);
    };
    // 4方向の近傍 UDLR
    const int dy[4] = {-1, 1, 0, 0};
    const int dx[4] = {0, 0, -1, 1};
    const int INF=1<<30;
    int ans=INF;
    auto bfs=[&](int i,int j){
        vector dist(H,vector<int>(W,INF));
        dist[i][j]=0;
        queue<pair<int,int>> que;
        que.push({i,j});
        while(que.size()){
            auto [y,x]=que.front();
            que.pop();
            for(int d=0;d<4;d++){
                uint ny=y+dy[d],nx=x+dx[d];
                if(outof(ny,nx)) continue;
                if(dist[ny][nx]>dist[y][x]+1){
                    dist[ny][nx]=dist[y][x]+1;
                    que.push({ny,nx});
                }
            }
        }
        return dist;
    };
    auto ds=bfs(A,B);
    auto dg=bfs(P,Q);
    for(int i=R1;i<=R2;i++) for(int j=C1;j<=C2;j++){
        ans=min(ans,ds[i][j]+dg[i][j]+dg[A][B]);
    }
    cout<<ans<<"\n";
}
0