結果

問題 No.2897 2集合間距離
ユーザー karinohitokarinohito
提出日時 2024-09-20 23:07:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 343 ms / 3,500 ms
コード長 1,209 bytes
コンパイル時間 2,113 ms
コンパイル使用メモリ 205,036 KB
実行使用メモリ 34,688 KB
最終ジャッジ日時 2024-09-20 23:07:34
合計ジャッジ時間 6,167 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
34,560 KB
testcase_01 AC 32 ms
34,560 KB
testcase_02 AC 31 ms
34,560 KB
testcase_03 AC 33 ms
34,688 KB
testcase_04 AC 32 ms
34,560 KB
testcase_05 AC 32 ms
34,560 KB
testcase_06 AC 32 ms
34,560 KB
testcase_07 AC 32 ms
34,432 KB
testcase_08 AC 33 ms
34,432 KB
testcase_09 AC 33 ms
34,560 KB
testcase_10 AC 33 ms
34,560 KB
testcase_11 AC 31 ms
34,560 KB
testcase_12 AC 33 ms
34,560 KB
testcase_13 AC 34 ms
34,560 KB
testcase_14 AC 38 ms
34,688 KB
testcase_15 AC 50 ms
34,432 KB
testcase_16 AC 343 ms
34,688 KB
testcase_17 AC 291 ms
34,560 KB
testcase_18 AC 286 ms
34,560 KB
testcase_19 AC 295 ms
34,560 KB
testcase_20 AC 317 ms
34,560 KB
testcase_21 AC 289 ms
34,560 KB
testcase_22 AC 276 ms
34,560 KB
testcase_23 AC 324 ms
34,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;




int main(){

    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll N;
    cin>>N;
    vector<vector<ll>> PL(2001,vector<ll>(2001,0));
    for(int i=0;i<N;i++){
        ll x,y;
        cin>>x>>y;
        PL[x+y+1][x-y+1000]++;
    }
    for(int i=0;i<2000;i++){
        for(int j=0;j<2001;j++){
            PL[i+1][j]+=PL[i][j];
        }
    }
    for(int i=0;i<2001;i++){
        for(int j=0;j<2000;j++){
            PL[i][j+1]+=PL[i][j];
        }
    }

    ll M;
    cin>>M;
    ll an=1e18;
    for(int i=0;i<M;i++){
        ll x,y;
        cin>>x>>y;
        ll a=x+y+1;
        ll b=x-y+1000;
        if(PL[a][b]+PL[a-1][b-1]-PL[a][b-1]-PL[a-1][b]>0){
            cout<<0<<endl;
            return 0;
        }
        ll L=0,R=5000;
        while(R-L>1){
            ll mid=(R+L)/2;
            ll r=min(a+mid,ll(2000));
            ll d=min(b+mid,ll(2000));
            ll l=max(0ll,a-mid-1);
            ll u=max(0ll,b-mid-1);
            ll sm=PL[r][d]+PL[l][u]-PL[r][u]-PL[l][d];
            if(sm>0)R=mid;
            else L=mid;
        }
        // cout<<R<<endl;
        an=min(an,R);
    }
    cout<<an<<endl;
}
0