Submission #992354

# Submission time Handle Problem Language Result Execution time Memory
992354 2024-06-04T10:00:46 Z Brinyon Road Construction (JOI21_road_construction) C++14
100 / 100
824 ms 15428 KB
#include<bits/stdc++.h>
#define MAXN 250001
using namespace std;
struct point{
    long long x,y;
};
long long dist(point a,point b){
    return abs(a.x-b.x)+abs(a.y-b.y);
}
long long n,k;
point a[MAXN];
bool cmp(point a,point b){
    if(a.x==b.x) return a.y<b.y;
    return a.x<b.x;
}
priority_queue<long long> pq;
int main(){
    cin>>n>>k;
    for(long long i=0;i<n;i++){
        long long x,y;
        cin>>a[i].x>>a[i].y;
    }
    sort(a,a+n,cmp);
    for(long long i=0;i<n;i++){
        for(long long i1=i-1;i1>=max(i-1000,(long long)0);i1--){
            long long dst=dist(a[i],a[i1]);
            if(pq.size()<k) pq.push(dst);
            else if(dst<pq.top()){
                pq.push(dst);
                pq.pop();
            }
        }
    }
    vector<long long> v;
    while(!pq.empty()){
        v.push_back(pq.top());
        pq.pop();
    }
    for(long long i=v.size()-1;i>=0;i--){
        cout<<v[i]<<"\n";
    }
    return 0;
}

Compilation message

road_construction.cpp: In function 'int main()':
road_construction.cpp:20:19: warning: unused variable 'x' [-Wunused-variable]
   20 |         long long x,y;
      |                   ^
road_construction.cpp:20:21: warning: unused variable 'y' [-Wunused-variable]
   20 |         long long x,y;
      |                     ^
road_construction.cpp:27:25: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   27 |             if(pq.size()<k) pq.push(dst);
      |                ~~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 87 ms 6980 KB Output is correct
2 Correct 65 ms 7012 KB Output is correct
3 Correct 47 ms 6980 KB Output is correct
4 Correct 50 ms 7000 KB Output is correct
5 Correct 66 ms 5956 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 765 ms 9532 KB Output is correct
2 Correct 812 ms 12392 KB Output is correct
3 Correct 45 ms 6980 KB Output is correct
4 Correct 714 ms 12396 KB Output is correct
5 Correct 637 ms 12352 KB Output is correct
6 Correct 622 ms 12608 KB Output is correct
7 Correct 735 ms 12288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 552 ms 4324 KB Output is correct
2 Correct 559 ms 4176 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 503 ms 4280 KB Output is correct
5 Correct 588 ms 4176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 552 ms 4324 KB Output is correct
2 Correct 559 ms 4176 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 503 ms 4280 KB Output is correct
5 Correct 588 ms 4176 KB Output is correct
6 Correct 569 ms 4196 KB Output is correct
7 Correct 554 ms 4176 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 592 ms 4176 KB Output is correct
11 Correct 493 ms 4152 KB Output is correct
12 Correct 561 ms 4176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 6980 KB Output is correct
2 Correct 65 ms 7012 KB Output is correct
3 Correct 47 ms 6980 KB Output is correct
4 Correct 50 ms 7000 KB Output is correct
5 Correct 66 ms 5956 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 468 ms 8516 KB Output is correct
8 Correct 432 ms 8508 KB Output is correct
9 Correct 49 ms 6972 KB Output is correct
10 Correct 459 ms 7740 KB Output is correct
11 Correct 518 ms 7744 KB Output is correct
12 Correct 305 ms 8512 KB Output is correct
13 Correct 342 ms 7612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 6980 KB Output is correct
2 Correct 65 ms 7012 KB Output is correct
3 Correct 47 ms 6980 KB Output is correct
4 Correct 50 ms 7000 KB Output is correct
5 Correct 66 ms 5956 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 765 ms 9532 KB Output is correct
8 Correct 812 ms 12392 KB Output is correct
9 Correct 45 ms 6980 KB Output is correct
10 Correct 714 ms 12396 KB Output is correct
11 Correct 637 ms 12352 KB Output is correct
12 Correct 622 ms 12608 KB Output is correct
13 Correct 735 ms 12288 KB Output is correct
14 Correct 552 ms 4324 KB Output is correct
15 Correct 559 ms 4176 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 503 ms 4280 KB Output is correct
18 Correct 588 ms 4176 KB Output is correct
19 Correct 569 ms 4196 KB Output is correct
20 Correct 554 ms 4176 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 592 ms 4176 KB Output is correct
24 Correct 493 ms 4152 KB Output is correct
25 Correct 561 ms 4176 KB Output is correct
26 Correct 468 ms 8516 KB Output is correct
27 Correct 432 ms 8508 KB Output is correct
28 Correct 49 ms 6972 KB Output is correct
29 Correct 459 ms 7740 KB Output is correct
30 Correct 518 ms 7744 KB Output is correct
31 Correct 305 ms 8512 KB Output is correct
32 Correct 342 ms 7612 KB Output is correct
33 Correct 824 ms 15428 KB Output is correct
34 Correct 815 ms 15332 KB Output is correct
35 Correct 812 ms 14656 KB Output is correct
36 Correct 642 ms 15408 KB Output is correct
37 Correct 633 ms 15404 KB Output is correct
38 Correct 724 ms 14528 KB Output is correct