제출 #1157881

#제출 시각아이디문제언어결과실행 시간메모리
1157881adiyerRoad Construction (JOI21_road_construction)C++20
5 / 100
3012 ms2105800 KiB
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> #define ordered_set tree < pair < ll, ll >, null_type, less < pair < ll, ll > >, rb_tree_tag, tree_order_statistics_node_update > #define all(x) x.begin(), x.end() #define len(s) (ll) s.size() #define pb push_back #define F first #define S second using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef double ld; const int N = 1e6 + 11; const int MAX = 2e4 + 11; const int P = 31; const int mod = 1e9 + 7; const ll inf = 1e18; ll n, k, lst, sz; ll x[N], y[N]; vector < pair < pair < ll, ll >, bool > > v; map < pair < ll, ll >, ll > mp; vector < ll > ans; ordered_set st; pair < ll, ll > it, it1, it2, it3, it4; ll f(ll d){ ll sum = 0; st.clear(), mp.clear(), v.clear(), sz = 0; for(ll i = 1; i <= n; i++){ it = {x[i] + y[i], x[i] - y[i]}; it1 = {x[i] + y[i] + d, x[i] - y[i] + d}; it2 = {x[i] + y[i] - d - 1, x[i] - y[i] - d - 1}; it3 = {x[i] + y[i] + d, x[i] - y[i] - d - 1}; it4 = {x[i] + y[i] - d - 1, x[i] - y[i] + d}; v.pb({it, 1}), v.pb({it1, 0}), v.pb({it2, 0}), v.pb({it3, 0}), v.pb({it4, 0}); } sort(all(v)); for(ll i = 0; i < len(v); i++){ ll j = i; while(i + 1 < len(v) && v[i].F.F == v[i + 1].F.F){ if(v[i].S) st.insert({v[i].F.S, ++sz}); i++; } if(v[i].S) st.insert({v[i].F.S, ++sz}); while(j <= i) mp[v[j].F] = st.order_of_key({v[j].F.S + 1, -inf}), j++; } for(ll i = 1; i <= n; i++){ it = {x[i] + y[i], x[i] - y[i]}; it1 = {x[i] + y[i] + d, x[i] - y[i] + d}; it2 = {x[i] + y[i] - d - 1, x[i] - y[i] - d - 1}; it3 = {x[i] + y[i] + d, x[i] - y[i] - d - 1}; it4 = {x[i] + y[i] - d - 1, x[i] - y[i] + d}; ll cur = mp[it1] + mp[it2] - mp[it3] - mp[it4]; sum += cur - 1; } return sum / 2; } vector < ll > dists; void solve(){ cin >> n >> k, lst = 0, ans.clear(); for(ll i = 1; i <= n; i++) cin >> x[i] >> y[i]; for(ll i = 1; i <= n; i++) for(ll j = i + 1; j <= n; j++) dists.pb(abs(x[i] - x[j]) + abs(y[i] - y[j])); sort(all(dists)); ll p = 2000; for(ll vals : dists){ if(p) f(vals), p--; ans.pb(vals), k--; if(k == 0){ for(ll val : ans) cout << val << '\n'; exit(0); } // lst = cnt; } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tt = 1; // cin >> tt; while(tt--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...