結果
| 問題 |
No.2897 2集合間距離
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-09-20 22:38:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 474 ms / 3,500 ms |
| コード長 | 1,576 bytes |
| コンパイル時間 | 4,473 ms |
| コンパイル使用メモリ | 252,716 KB |
| 最終ジャッジ日時 | 2025-02-24 10:28:28 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 |
ソースコード
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
template<typename T>
bool chmin(T &x, T y) { return x > y ? (x = y, true) : false; }
template<typename T>
bool chmax(T &x, T y) { return x < y ? (x = y, true) : false; }
struct io_setup {
io_setup() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout << fixed << setprecision(15);
}
} io_setup;
int main(){
int n;
cin>>n;
int sz=2e3+10;
vector<vector<int>> fld(sz,vector<int>(sz));
int shf=1e3+5;
rep(i,0,n){
int x,y;
cin>>x>>y;
fld.at(x+y+5).at(x-y+shf)++;
}
rep(i,1,sz) rep(j,0,sz) fld.at(i).at(j)+=fld.at(i-1).at(j);
rep(i,0,sz) rep(j,1,sz) fld.at(i).at(j)+=fld.at(i).at(j-1);
//rep(i,0,sz){
// rep(j,0,sz){
// cout<<fld.at(i).at(j)<<" ";
// }
// cout<<endl;
//}
int ans=1e9;
int m;
cin>>m;
rep(lp,0,m){
int z,w;
cin>>z>>w;
int nz=z+w+5,nw=z-w+shf;
vector<int> dd={0,1,0,-1,0};
auto check=[&](int d) ->int {
int tmp=0;
{
int nnz=max(nz-d-1,0);
int nnw=max(nw-d-1,0);
tmp+=fld.at(nnz).at(nnw);
}
{
int nnz=max(nz-d-1,0);
int nnw=min(nw+d,sz-1);
tmp-=fld.at(nnz).at(nnw);
}
{
int nnz=min(nz+d,sz-1);
int nnw=max(nw-d-1,0);
tmp-=fld.at(nnz).at(nnw);
}
{
int nnz=min(nz+d,sz-1);
int nnw=min(nw+d,sz-1);
tmp+=fld.at(nnz).at(nnw);
}
return tmp>0;
};
int up=1e5;
int dw=-1;
while(up-dw>1){
int md=(up+dw)/2;
if(check(md)) up=md;
else dw=md;
}
chmin(ans,up);
}
cout<<ans<<endl;
}