結果
問題 | No.2612 Close the Distance |
ユーザー |
![]() |
提出日時 | 2023-06-15 19:38:08 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 652 ms / 3,000 ms |
コード長 | 2,356 bytes |
コンパイル時間 | 4,267 ms |
コンパイル使用メモリ | 233,604 KB |
実行使用メモリ | 22,860 KB |
最終ジャッジ日時 | 2024-09-28 05:13:16 |
合計ジャッジ時間 | 16,422 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
コンパイルメッセージ
main.cpp: In function 'bool sub(std::vector<std::pair<long long int, long long int> >&, int)': main.cpp:36:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 36 | for(auto [w,v]:p){ | ^ main.cpp:45:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 45 | for(auto [w,v]:p){ | ^ main.cpp: In function 'int main()': main.cpp:86:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 86 | for(auto [w,v]:p){ | ^
ソースコード
//g++ 1.cpp -std=c++17 -O2 -I . #include <bits/stdc++.h> using namespace std; #include <atcoder/all> using namespace atcoder; using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vld = vector<ld>; using vvld = vector<vld>; using vst = vector<string>; using vvst = vector<vst>; #define fi first #define se second #define pb push_back #define eb emplace_back #define pq_big(T) priority_queue<T,vector<T>,less<T>> #define pq_small(T) priority_queue<T,vector<T>,greater<T>> #define all(a) a.begin(),a.end() #define rep(i,start,end) for(ll i=start;i<(ll)(end);i++) #define per(i,start,end) for(ll i=start;i>=(ll)(end);i--) #define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end()) bool sub(vector<pair<ll,ll>> &p,int a){ int n=p.size(); ll min_w=1e18,max_w=-1e18; ll min_v=1e18,max_v=-1e18; for(auto [w,v]:p){ min_w=min(min_w,w); max_w=max(max_w,w); min_v=min(min_v,v); max_v=max(max_v,v); } bool flg=0,flg2=1,flg3=1,flg4,flg5; for(auto [w,v]:p){ flg4=0,flg5=0; if(abs(min_w-w)<=a&&abs(min_v-v)<=a)flg4=1; if(abs(max_w-w)<=a&&abs(max_v-v)<=a)flg4=1; if(abs(min_w-w)<=a&&abs(max_v-v)<=a)flg5=1; if(abs(max_w-w)<=a&&abs(min_v-v)<=a)flg5=1; flg2=min(flg2,flg4); flg3=min(flg3,flg5); } flg=max({flg,flg2,flg3}); return flg; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n;cin>>n; ll min_w=1e18,max_w=-1e18; ll min_v=1e18,max_v=-1e18; vector<pair<ll,ll>> p(n); rep(i,0,n){ ll x,y;cin>>x>>y; ll w=x+y,v=x-y; p[i]={w,v}; min_w=min(min_w,w); max_w=max(max_w,w); min_v=min(min_v,v); max_v=max(max_v,v); } ll ng=-1,ok=1e18; while(ok-ng>1){ ll check=(ok+ng)/2; int flg=0; vector<pair<ll,ll>> p1,p2,p3,p4; for(auto [w,v]:p){ if(abs(min_w-w)>check||abs(min_v-v)>check)p1.emplace_back(w,v); if(abs(min_w-w)>check||abs(max_v-v)>check)p2.emplace_back(w,v); if(abs(max_w-w)>check||abs(min_v-v)>check)p3.emplace_back(w,v); if(abs(max_w-w)>check||abs(max_v-v)>check)p4.emplace_back(w,v); } flg=max({flg,(int)sub(p1,check),(int)sub(p2,check),(int)sub(p3,check),(int)sub(p4,check)}); if(flg){ ok=check; } else{ ng=check; } } cout<<ok<<endl; }