Submission #429817

#TimeUsernameProblemLanguageResultExecution timeMemory
429817talant117408Road Construction (JOI21_road_construction)C++17
7 / 100
640 ms49604 KiB
/* Code written by Talant I.D. */ #include <bits/stdc++.h> //~ #include <ext/pb_ds/assoc_container.hpp> //~ using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; //~ typedef tree <int, null_type, less_equal <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define precision(n) fixed << setprecision(n) #define pb push_back #define ub upper_bound #define lb lower_bound #define mp make_pair #define eps (double)1e-9 #define PI 2*acos(0.0) #define endl "\n" #define sz(v) int((v).size()) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define OK cout << "OK" << endl; const ll mod = 1e9+7; ll mode(ll a) { while (a < 0) { a += mod; } return a % mod; } ll subt(ll a, ll b) { return mode(mode(a)-mode(b)); } ll add(ll a, ll b) { return mode(mode(a)+mode(b)); } ll mult(ll a, ll b) { return mode(mode(a)*mode(b)); } ll binpow(ll a, ll b) { ll res = 1; while (b) { if (b&1) res = mult(res, a); a = mult(a, a); b >>= 1; } return res; } int main() { do_not_disturb int n, k; cin >> n >> k; vector <pll> pos(n); for (int i = 0; i < n; i++) { cin >> pos[i].first >> pos[i].second; } sort(all(pos)); vector <ll> Xs; map <ll, vector <ll>> byX; for (auto to : pos) { if (sz(Xs) == 0 || Xs.back() != to.first) { Xs.pb(to.first); } byX[to.first].pb(to.second); } multiset <ll, greater <ll>> st; for (int i = 0; i < sz(Xs); i++) { auto x1 = Xs[i], x2 = (i < sz(Xs)-1 ? Xs[i+1] : 0); for (int j = 0; j < sz(byX[x1])-1; j++) { st.insert(abs(byX[x1][j]-byX[x1][j+1])); if (sz(st) > k) { st.erase(st.find(*st.begin())); } } if (i < sz(Xs)-1) { for (int j = 0; j < sz(byX[x1]); j++) { auto it = lb(all(byX[x2]), byX[x1][j]); if (it != byX[x2].end()) { st.insert(abs(byX[x1][j]-(*it))+x2-x1); if (sz(st) > k) { st.erase(st.find(*st.begin())); } it++; if (it != byX[x2].end()) { st.insert(abs(byX[x1][j]-(*it))+x2-x1); if (sz(st) > k) { st.erase(st.find(*st.begin())); } } it--; } if (it != byX[x2].begin()) { it--; st.insert(abs(byX[x1][j]-(*it))+x2-x1); if (sz(st) > k) { st.erase(st.find(*st.begin())); } } } } } auto it = st.end(); it--; for (; it != st.begin(); it--) { cout << *it << endl; } cout << *it << endl; return 0; }
#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...