답안 #921960

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
921960 2024-02-04T15:06:38 Z Darren0724 Road Construction (JOI21_road_construction) C++17
100 / 100
1806 ms 15468 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define abcorz ios_base::sync_with_stdio(false);cin.tie(0);
int n,k;
vector<pair<int,int>> v;
vector<int> ans;
const int INF=1e18;
int calc(pair<int,int> a,pair<int,int> b){
    return max(abs(a.x-b.x),abs(a.y-b.y));
}
int f(int p){
    ans.clear();
    set<pair<int,int>> s;
    for(int i=0,j=0;i<n;i++){
        while(v[i].y-v[j].y>p){
            s.erase(v[j++]);
        }
        auto it=s.lower_bound({v[i].x-p,-INF});
        auto it1=s.upper_bound({v[i].x+p,INF});
        while(it!=it1){
            ans.push_back(calc(*it,v[i]));
            it++;
        }
        if(ans.size()>=k)return 1;
        s.insert(v[i]);
    }
    return 0;
}
int32_t main(){
    abcorz;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        int a,b;cin>>a>>b;
        v.push_back({a-b,a+b});
    }
    sort(all(v),[](pair<int,int> a,pair<int,int> b){return a.y<b.y;});
    int l=0,r=4e9;
    while(r-l>1){
        int m=(l+r)>>1;
        (f(m)?r:l)=m;
    }
    f(l);
    while(ans.size()<k)ans.push_back(r);
    sort(all(ans));
    for(int j:ans){
        cout<<j<<'\n';
    }

    return 0;
}

Compilation message

road_construction.cpp: In function 'long long int f(long long int)':
road_construction.cpp:28:22: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   28 |         if(ans.size()>=k)return 1;
      |            ~~~~~~~~~~^~~
road_construction.cpp: In function 'int32_t main()':
road_construction.cpp:47:21: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   47 |     while(ans.size()<k)ans.push_back(r);
      |           ~~~~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 5168 KB Output is correct
2 Correct 92 ms 5156 KB Output is correct
3 Correct 77 ms 5160 KB Output is correct
4 Correct 75 ms 5072 KB Output is correct
5 Correct 78 ms 3964 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 292 ms 9568 KB Output is correct
2 Correct 301 ms 9404 KB Output is correct
3 Correct 71 ms 4976 KB Output is correct
4 Correct 228 ms 12392 KB Output is correct
5 Correct 266 ms 12484 KB Output is correct
6 Correct 250 ms 12476 KB Output is correct
7 Correct 263 ms 12244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 182 ms 5188 KB Output is correct
2 Correct 255 ms 4512 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 111 ms 8240 KB Output is correct
5 Correct 569 ms 9776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 182 ms 5188 KB Output is correct
2 Correct 255 ms 4512 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 111 ms 8240 KB Output is correct
5 Correct 569 ms 9776 KB Output is correct
6 Correct 351 ms 9416 KB Output is correct
7 Correct 344 ms 9408 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 261 ms 9628 KB Output is correct
11 Correct 92 ms 7364 KB Output is correct
12 Correct 685 ms 9660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 5168 KB Output is correct
2 Correct 92 ms 5156 KB Output is correct
3 Correct 77 ms 5160 KB Output is correct
4 Correct 75 ms 5072 KB Output is correct
5 Correct 78 ms 3964 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 849 ms 7960 KB Output is correct
8 Correct 856 ms 7960 KB Output is correct
9 Correct 74 ms 5072 KB Output is correct
10 Correct 398 ms 7456 KB Output is correct
11 Correct 249 ms 7400 KB Output is correct
12 Correct 621 ms 7976 KB Output is correct
13 Correct 577 ms 7068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 5168 KB Output is correct
2 Correct 92 ms 5156 KB Output is correct
3 Correct 77 ms 5160 KB Output is correct
4 Correct 75 ms 5072 KB Output is correct
5 Correct 78 ms 3964 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 292 ms 9568 KB Output is correct
8 Correct 301 ms 9404 KB Output is correct
9 Correct 71 ms 4976 KB Output is correct
10 Correct 228 ms 12392 KB Output is correct
11 Correct 266 ms 12484 KB Output is correct
12 Correct 250 ms 12476 KB Output is correct
13 Correct 263 ms 12244 KB Output is correct
14 Correct 182 ms 5188 KB Output is correct
15 Correct 255 ms 4512 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 111 ms 8240 KB Output is correct
18 Correct 569 ms 9776 KB Output is correct
19 Correct 351 ms 9416 KB Output is correct
20 Correct 344 ms 9408 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 261 ms 9628 KB Output is correct
24 Correct 92 ms 7364 KB Output is correct
25 Correct 685 ms 9660 KB Output is correct
26 Correct 849 ms 7960 KB Output is correct
27 Correct 856 ms 7960 KB Output is correct
28 Correct 74 ms 5072 KB Output is correct
29 Correct 398 ms 7456 KB Output is correct
30 Correct 249 ms 7400 KB Output is correct
31 Correct 621 ms 7976 KB Output is correct
32 Correct 577 ms 7068 KB Output is correct
33 Correct 1794 ms 15248 KB Output is correct
34 Correct 1806 ms 15244 KB Output is correct
35 Correct 1051 ms 14496 KB Output is correct
36 Correct 1022 ms 15468 KB Output is correct
37 Correct 952 ms 15252 KB Output is correct
38 Correct 1000 ms 14016 KB Output is correct