답안 #972086

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
972086 2024-04-30T04:19:35 Z huutuan Road Construction (JOI21_road_construction) C++14
100 / 100
1506 ms 13660 KB
#include<bits/stdc++.h>

using namespace std;

#define int long long

const int N=25e4+10;
int n, k;
pair<int, int> a[N];

bool check(int mid, bool trace, vector<int> &ans){
   int cnt=0;
   set<pair<int, int>> st;
   for (int i=1, j=1; i<=n; ++i){
      while (a[i].first-a[j].first>mid){
         st.erase({a[j].second, j});
         ++j;
      }
      auto it=st.lower_bound({a[i].second-mid, (int)0});
      while (it!=st.end() && abs(it->first-a[i].second)<=mid){
         ++cnt;
         if (!trace && cnt>=k) return true;
         if (trace) ans.push_back(max(abs(a[i].first-a[it->second].first), abs(a[i].second-it->first)));
         ++it;
      }
      st.insert({a[i].second, i});
   }
   return false;
}

int32_t main(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   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);
   int l=1, r=4e9;
   vector<int> ans;
   while (l<=r){
      int mid=(l+r)>>1;
      if (check(mid, 0, ans)) r=mid-1;
      else l=mid+1;
   }
   check(r, 1, ans);
   sort(ans.begin(), ans.end());
   ans.resize(k, l);
   for (int i:ans) cout << i << '\n';
   return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 5056 KB Output is correct
2 Correct 96 ms 5052 KB Output is correct
3 Correct 73 ms 5076 KB Output is correct
4 Correct 71 ms 5252 KB Output is correct
5 Correct 72 ms 4032 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 293 ms 10728 KB Output is correct
2 Correct 282 ms 10512 KB Output is correct
3 Correct 62 ms 5072 KB Output is correct
4 Correct 228 ms 10392 KB Output is correct
5 Correct 240 ms 10516 KB Output is correct
6 Correct 238 ms 10712 KB Output is correct
7 Correct 223 ms 9944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 183 ms 9436 KB Output is correct
2 Correct 251 ms 9608 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 116 ms 7164 KB Output is correct
5 Correct 258 ms 9720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 183 ms 9436 KB Output is correct
2 Correct 251 ms 9608 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 116 ms 7164 KB Output is correct
5 Correct 258 ms 9720 KB Output is correct
6 Correct 332 ms 9436 KB Output is correct
7 Correct 317 ms 9436 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 260 ms 9284 KB Output is correct
11 Correct 96 ms 7260 KB Output is correct
12 Correct 284 ms 9552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 5056 KB Output is correct
2 Correct 96 ms 5052 KB Output is correct
3 Correct 73 ms 5076 KB Output is correct
4 Correct 71 ms 5252 KB Output is correct
5 Correct 72 ms 4032 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 748 ms 8708 KB Output is correct
8 Correct 706 ms 8700 KB Output is correct
9 Correct 71 ms 5272 KB Output is correct
10 Correct 368 ms 7944 KB Output is correct
11 Correct 226 ms 8180 KB Output is correct
12 Correct 275 ms 8704 KB Output is correct
13 Correct 374 ms 7272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 5056 KB Output is correct
2 Correct 96 ms 5052 KB Output is correct
3 Correct 73 ms 5076 KB Output is correct
4 Correct 71 ms 5252 KB Output is correct
5 Correct 72 ms 4032 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 293 ms 10728 KB Output is correct
8 Correct 282 ms 10512 KB Output is correct
9 Correct 62 ms 5072 KB Output is correct
10 Correct 228 ms 10392 KB Output is correct
11 Correct 240 ms 10516 KB Output is correct
12 Correct 238 ms 10712 KB Output is correct
13 Correct 223 ms 9944 KB Output is correct
14 Correct 183 ms 9436 KB Output is correct
15 Correct 251 ms 9608 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 116 ms 7164 KB Output is correct
18 Correct 258 ms 9720 KB Output is correct
19 Correct 332 ms 9436 KB Output is correct
20 Correct 317 ms 9436 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 260 ms 9284 KB Output is correct
24 Correct 96 ms 7260 KB Output is correct
25 Correct 284 ms 9552 KB Output is correct
26 Correct 748 ms 8708 KB Output is correct
27 Correct 706 ms 8700 KB Output is correct
28 Correct 71 ms 5272 KB Output is correct
29 Correct 368 ms 7944 KB Output is correct
30 Correct 226 ms 8180 KB Output is correct
31 Correct 275 ms 8704 KB Output is correct
32 Correct 374 ms 7272 KB Output is correct
33 Correct 1506 ms 13456 KB Output is correct
34 Correct 1499 ms 13508 KB Output is correct
35 Correct 956 ms 12768 KB Output is correct
36 Correct 452 ms 13660 KB Output is correct
37 Correct 444 ms 13396 KB Output is correct
38 Correct 574 ms 12100 KB Output is correct