제출 #1157713

#제출 시각아이디문제언어결과실행 시간메모리
1157713Kaztaev_AlisherRoad Construction (JOI21_road_construction)C++20
5 / 100
2515 ms2103360 KiB
#include <bits/stdc++.h> #define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) #define all(a) a.begin() , a.end() #define F first #define S second #define int ll using namespace std; using ll = long long; const ll N = 2e5+5 , inf = 2e9 + 7; const ll INF = 1e18 , mod = 1e9+7; int x[N] , y[N] , ord[N] , nxt[N]; int n , k; int get(int i , int j){ return abs(x[i]-x[j]) + abs(y[i]-y[j]); } void slow(){ vector<pair<int,int>> v; for(int i = 1; i <= n; i++){ for(int j = i+1; j <= n; j++){ v.push_back({i,j}); } } sort(all(v),[&](pair<int,int> i , pair<int,int> j){ return (get(i.F , i.S) < get(j.F , j.S)); }); for(int i = 0; i < k; i++){ cout << get(v[i].F,v[i].S) << "\n"; } } void k_one(){ for(int i = 1; i <= n; i++){ ord[i] = i; } sort(ord+1,ord+1+n,[&](int i , int j){ if(x[i] == x[j]) return y[i] < y[j]; return x[i] < x[j]; }); int ans = inf; set<pair<int,int>> st; for(int _ = 1 , j = 1; _ <= n; _++){ int i = ord[_]; while(x[i]-x[ord[j]] > ans){ st.erase({y[ord[j]],ord[j]}); j++; } auto it = st.lower_bound({y[i]-ans,0}); while(it != st.end() && it->F < y[i]+ans){ ans = min(ans , get(i,it->S)); it++; } st.insert({y[i],i}); } cout << ans << "\n"; } void only_x(){ sort(x+1,x+1+n); set<pair<int,int>> st; for(int i = 1; i <= n; i++){ nxt[i] = i+1; if(nxt[i] <= n){ st.insert({x[nxt[i]]-x[i] , i}); } } while(k--){ int i = st.begin()->S; st.erase(st.begin()); cout << x[nxt[i]] - x[i] <<"\n"; nxt[i]++; if(nxt[i] <= n) st.insert({x[nxt[i]]-x[i] , i}); } } void solve(){ cin >> n >> k; int cnt = 0; for(int i = 1; i <= n; i++){ cin >> x[i] >> y[i]; if(y[i] == 0){ cnt++; } } if(k == 1){ k_one(); } else if(cnt == n){ only_x(); } else { slow(); } } /* */ signed main(){ ios; 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...