# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
557434 | 2022-05-05T10:30:01 Z | 600Mihnea | Road Construction (JOI21_road_construction) | C++17 | 10000 ms | 322980 KB |
#include <bits/stdc++.h> bool home = 1; using namespace std; typedef long long ll; const int N=250000+7; struct T{ ll x; ll y; }; bool cmpTx(T a,T b) { return a.x<b.x; } int n; int k; T a[N]; const ll INF=(ll)1e10; const ll H=(ll)3e9; map<ll, int> aib; void clr() { aib.clear(); } void add(ll i,int x) { i+=H; assert(i>0); while (i<=INF) { aib[i]+=x; i+=i&(-i); } } int get(ll i) { i+=H; if(i<=0) return 0; assert(i>0); int sol=0; while(i) { sol+=aib[i]; i-=i&(-i); } return sol; } ll how_many_under(ll d) { clr(); ll sol=0; int pt=1; for (int i=1;i<=n;i++) { while (a[i].x-a[pt].x>d) add(a[pt++].y,-1); sol+=get(a[i].y+d)-get(a[i].y-d-1); add(a[i].y,+1); } return sol; } signed main() { #ifdef ONLINE_JUDGE home = 0; #endif home=0; if (home) { freopen("I_am_iron_man", "r", stdin); } else { ios::sync_with_stdio(0); cin.tie(0); } cin>>n>>k; for (int i=1;i<=n;i++) { int x,y; cin>>x>>y; a[i]={x+y, x-y}; } sort(a+1,a+n+1,cmpTx); ll low=0,high=(ll)1e10,sol=-1; while (low<=high) { ll mid=(low+high)/2; if(how_many_under(mid)<=k) { sol=mid; low=mid+1; }else{ high=mid-1; } } vector<ll> v; int pt=1; for (int i=1;i<=n;i++) { while (a[i].x-a[pt].x>sol) pt++; for (int j=pt;j<i;j++) { if(abs(a[i].y-a[j].y)<=sol){ v.push_back(max(a[i].x-a[j].x,abs(a[i].y-a[j].y))); } } } sort(v.begin(),v.end()); assert((int)v.size()<=k); v.resize(k, sol+1); for (auto &x: v) { cout<<x<<"\n"; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 326 ms | 7044 KB | Output is correct |
2 | Correct | 309 ms | 7236 KB | Output is correct |
3 | Correct | 143 ms | 6092 KB | Output is correct |
4 | Correct | 136 ms | 6100 KB | Output is correct |
5 | Correct | 228 ms | 4912 KB | Output is correct |
6 | Correct | 78 ms | 412 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 10093 ms | 322980 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 10088 ms | 311668 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 10088 ms | 311668 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 326 ms | 7044 KB | Output is correct |
2 | Correct | 309 ms | 7236 KB | Output is correct |
3 | Correct | 143 ms | 6092 KB | Output is correct |
4 | Correct | 136 ms | 6100 KB | Output is correct |
5 | Correct | 228 ms | 4912 KB | Output is correct |
6 | Correct | 78 ms | 412 KB | Output is correct |
7 | Execution timed out | 10104 ms | 144180 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 326 ms | 7044 KB | Output is correct |
2 | Correct | 309 ms | 7236 KB | Output is correct |
3 | Correct | 143 ms | 6092 KB | Output is correct |
4 | Correct | 136 ms | 6100 KB | Output is correct |
5 | Correct | 228 ms | 4912 KB | Output is correct |
6 | Correct | 78 ms | 412 KB | Output is correct |
7 | Execution timed out | 10093 ms | 322980 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |