Submission #794815

# Submission time Handle Problem Language Result Execution time Memory
794815 2023-07-26T23:40:09 Z fuad27 Road Construction (JOI21_road_construction) C++17
13 / 100
2154 ms 26084 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++) {
    int x, y;
    cin >> x >> y;
    p.push_back({x+y, y-x});
  }
  sort(p.begin(), p.end());
  long long lo = 0, hi = 5e9;
  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 89 ms 5024 KB Output is correct
2 Correct 82 ms 5028 KB Output is correct
3 Incorrect 77 ms 5136 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 810 ms 26084 KB Output is correct
2 Correct 806 ms 26040 KB Output is correct
3 Correct 67 ms 4896 KB Output is correct
4 Correct 789 ms 25780 KB Output is correct
5 Correct 878 ms 26040 KB Output is correct
6 Correct 915 ms 26044 KB Output is correct
7 Correct 788 ms 25400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1964 ms 22688 KB Output is correct
2 Correct 1978 ms 22856 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 818 ms 22740 KB Output is correct
5 Correct 1788 ms 25116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1964 ms 22688 KB Output is correct
2 Correct 1978 ms 22856 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 818 ms 22740 KB Output is correct
5 Correct 1788 ms 25116 KB Output is correct
6 Correct 2149 ms 22964 KB Output is correct
7 Correct 2154 ms 22720 KB Output is correct
8 Correct 0 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 89 ms 5024 KB Output is correct
2 Correct 82 ms 5028 KB Output is correct
3 Incorrect 77 ms 5136 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 89 ms 5024 KB Output is correct
2 Correct 82 ms 5028 KB Output is correct
3 Incorrect 77 ms 5136 KB Output isn't correct
4 Halted 0 ms 0 KB -