結果
問題 | No.2897 2集合間距離 |
ユーザー |
![]() |
提出日時 | 2024-09-26 18:21:26 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,168 bytes |
コンパイル時間 | 3,161 ms |
コンパイル使用メモリ | 246,960 KB |
実行使用メモリ | 6,272 KB |
最終ジャッジ日時 | 2024-09-26 18:21:35 |
合計ジャッジ時間 | 7,215 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 WA * 1 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define fi first #define sc second #define pii pair<int,int> #define pb push_back #define umap unordered_map #define mset multiset #define pq priority_queue #define ull unsigned long long #define i128 __int128 const int maxn=2e5+10; int n,x[maxn],m,y[maxn]; vector<int> vec[maxn]; void solve(){ cin>>n; for(int i=1;i<=n;i++) cin>>x[i]>>y[i]; cin>>m; for(int i=1;i<=m;i++){ int a,b; cin>>a>>b; vec[a].pb(b); } int res=1e9; for(int i=1;i<=n;i++){ for(int j=0;j<=1e3;j++){ if(j-x[i]>res) break; else if(x[i]-j>res) continue; if(vec[j].empty()) continue; auto p=upper_bound(vec[j].begin(),vec[j].end(),y[i]); if(p!=vec[j].end()) res=min(res,abs(x[i]-j)+abs(y[i]-(*p))); if(p!=vec[j].begin()) p--,res=min(res,abs(x[i]-j)+abs(y[i]-(*p))); } } cout<<res<<endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); int t=1; // cin>>t; while(t--) solve(); return 0; } /* Samples input: output: THINGS TODO: ??freopen??????? ???? ???????????? */