Submission #794817

# Submission time Handle Problem Language Result Execution time Memory
794817 2023-07-26T23:42:48 Z fuad27 Road Construction (JOI21_road_construction) C++17
13 / 100
2544 ms 23052 KB
#include<bits/stdc++.h>
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
const int N=250010;
int n, k;
vector<pair<long long,long long>> p;
vector<long long> res;
const long long inf=1e18;
bool check(long long dist) {
  res.clear();
  multiset<pair<long long, long long>> s;
  int p1=0;
  for(int i = 0;i<(int)p.size();i++) {
    while(p[i].first-p[p1].first>dist) {
      s.erase(s.find({p[p1].second, p[p1].first}));
      p1++;
    }
    auto it1=s.lower_bound({p[i].second-dist, -inf}), it2=s.upper_bound({p[i].second+dist+1, -inf});
    while(it1!=it2 and (int)res.size()<k) {
      res.push_back(max(abs(p[i].first-(*it1).second), abs(p[i].second-(*it1).first)));
      it1++;
    }
    s.insert({p[i].second, p[i].first});
  }
  return (int)res.size()==k;
}
int main () {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> k;
  for(int i = 0;i<n;i++) {
    long long x, y;
    cin >> x >> y;
    p.push_back({x+y, y-x});
  }
  sort(p.begin(), p.end());
  long long lo = 0, hi = 1e10;
  while(lo < hi) {
    long long mid=(lo+hi-1)>>1;
    if(check(mid)) {
      hi=mid;
    }
    else {
      lo=mid+1;
    }
  }
  check(lo-1);
  sort(res.begin(), res.end());
  for(int i:res)cout << i << "\n";
  for(int i = res.size();i<k;i++)cout << lo << "\n";
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 87 ms 5004 KB Output is correct
2 Correct 84 ms 4996 KB Output is correct
3 Incorrect 78 ms 5008 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 866 ms 23000 KB Output is correct
2 Correct 912 ms 23004 KB Output is correct
3 Correct 68 ms 4888 KB Output is correct
4 Correct 835 ms 22748 KB Output is correct
5 Correct 945 ms 23052 KB Output is correct
6 Correct 969 ms 23004 KB Output is correct
7 Correct 860 ms 22232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2159 ms 19852 KB Output is correct
2 Correct 2285 ms 19884 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 902 ms 19764 KB Output is correct
5 Correct 1875 ms 19768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2159 ms 19852 KB Output is correct
2 Correct 2285 ms 19884 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 902 ms 19764 KB Output is correct
5 Correct 1875 ms 19768 KB Output is correct
6 Correct 2544 ms 19792 KB Output is correct
7 Correct 2529 ms 19768 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 87 ms 5004 KB Output is correct
2 Correct 84 ms 4996 KB Output is correct
3 Incorrect 78 ms 5008 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 87 ms 5004 KB Output is correct
2 Correct 84 ms 4996 KB Output is correct
3 Incorrect 78 ms 5008 KB Output isn't correct
4 Halted 0 ms 0 KB -