답안 #589267

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
589267 2022-07-04T11:21:51 Z Peti Road Construction (JOI21_road_construction) C++14
100 / 100
2132 ms 23232 KB
    #include <bits/stdc++.h>

    using namespace std;

    struct pont{
        long long x, y;
        bool operator<(const pont &p) const{
            if(x != p.x) return x < p.x;
            return y < p.y;
        }
    };

    vector<long long> megold(vector<pont> &v, int n, long long d, int k){
        //cout<<"start dist: "<<d<<'\n';
        set<pont> s;
        vector<long long> ret;
        for(pont p : v){
            auto it = s.lower_bound({p.x-d, -(long long)5e9});
            //cout<<"p: "<<p.x<<' '<<p.y<<"------------\n";
            while(it != s.end() && it->x <= p.x+d){
                //cout<<it->x<<' '<<it->y<<'\n';
                if(it->y < p.y-d){
                    it++;
                    s.erase(prev(it));
                } else{
                    ret.push_back(max(abs(p.x - it->x), abs(p.y - it->y)));
                    if(ret.size() > k) return ret;
                    it++;
                }
            }
            s.insert(p);
        }
        return ret;
    }

    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);

        int n, k;
        cin>>n>>k;

        vector<pont> v(n);
        for(int i = 0; i < n; i++){
            long long x, y;
            cin>>x>>y;
            v[i].x = x+y;
            v[i].y = x-y;
        }

        sort(v.begin(), v.end(), [](pont a, pont b) -> bool{ return a.y < b.y; });

        long long l = 0, r = (long long)5e9;
        while(l+1ll < r){
            long long m = (l+r)/2;
            vector<long long> tmp = megold(v, n, m, k);
            if(tmp.size() <= k)
                l = m;
            else
                r = m;
        }

        vector<long long> ki = megold(v, n, l, k);
        ki.resize(k, l+1ll);

        sort(ki.begin(), ki.end());
        for(long long x : ki) cout<<x<<'\n';

        return 0;
    }

Compilation message

road_construction.cpp: In function 'std::vector<long long int> megold(std::vector<pont>&, int, long long int, int)':
road_construction.cpp:27:35: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |                     if(ret.size() > k) return ret;
      |                        ~~~~~~~~~~~^~~
road_construction.cpp: In function 'int main()':
road_construction.cpp:57:27: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |             if(tmp.size() <= k)
      |                ~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 161 ms 6888 KB Output is correct
2 Correct 157 ms 6944 KB Output is correct
3 Correct 145 ms 7140 KB Output is correct
4 Correct 137 ms 7020 KB Output is correct
5 Correct 156 ms 5780 KB Output is correct
6 Correct 3 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1681 ms 23088 KB Output is correct
2 Correct 1659 ms 23088 KB Output is correct
3 Correct 128 ms 6848 KB Output is correct
4 Correct 1438 ms 22872 KB Output is correct
5 Correct 1471 ms 23232 KB Output is correct
6 Correct 1389 ms 23072 KB Output is correct
7 Correct 1045 ms 22424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1404 ms 12312 KB Output is correct
2 Correct 1852 ms 12368 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 677 ms 19836 KB Output is correct
5 Correct 504 ms 4180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1404 ms 12312 KB Output is correct
2 Correct 1852 ms 12368 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 677 ms 19836 KB Output is correct
5 Correct 504 ms 4180 KB Output is correct
6 Correct 1444 ms 9432 KB Output is correct
7 Correct 1416 ms 9344 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 2132 ms 12544 KB Output is correct
11 Correct 780 ms 19916 KB Output is correct
12 Correct 587 ms 4232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 161 ms 6888 KB Output is correct
2 Correct 157 ms 6944 KB Output is correct
3 Correct 145 ms 7140 KB Output is correct
4 Correct 137 ms 7020 KB Output is correct
5 Correct 156 ms 5780 KB Output is correct
6 Correct 3 ms 336 KB Output is correct
7 Correct 666 ms 10064 KB Output is correct
8 Correct 719 ms 10060 KB Output is correct
9 Correct 144 ms 7044 KB Output is correct
10 Correct 612 ms 9480 KB Output is correct
11 Correct 470 ms 11860 KB Output is correct
12 Correct 426 ms 8016 KB Output is correct
13 Correct 384 ms 8576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 161 ms 6888 KB Output is correct
2 Correct 157 ms 6944 KB Output is correct
3 Correct 145 ms 7140 KB Output is correct
4 Correct 137 ms 7020 KB Output is correct
5 Correct 156 ms 5780 KB Output is correct
6 Correct 3 ms 336 KB Output is correct
7 Correct 1681 ms 23088 KB Output is correct
8 Correct 1659 ms 23088 KB Output is correct
9 Correct 128 ms 6848 KB Output is correct
10 Correct 1438 ms 22872 KB Output is correct
11 Correct 1471 ms 23232 KB Output is correct
12 Correct 1389 ms 23072 KB Output is correct
13 Correct 1045 ms 22424 KB Output is correct
14 Correct 1404 ms 12312 KB Output is correct
15 Correct 1852 ms 12368 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 677 ms 19836 KB Output is correct
18 Correct 504 ms 4180 KB Output is correct
19 Correct 1444 ms 9432 KB Output is correct
20 Correct 1416 ms 9344 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 2132 ms 12544 KB Output is correct
24 Correct 780 ms 19916 KB Output is correct
25 Correct 587 ms 4232 KB Output is correct
26 Correct 666 ms 10064 KB Output is correct
27 Correct 719 ms 10060 KB Output is correct
28 Correct 144 ms 7044 KB Output is correct
29 Correct 612 ms 9480 KB Output is correct
30 Correct 470 ms 11860 KB Output is correct
31 Correct 426 ms 8016 KB Output is correct
32 Correct 384 ms 8576 KB Output is correct
33 Correct 1424 ms 15436 KB Output is correct
34 Correct 1359 ms 15356 KB Output is correct
35 Correct 1327 ms 15136 KB Output is correct
36 Correct 755 ms 13780 KB Output is correct
37 Correct 727 ms 13464 KB Output is correct
38 Correct 858 ms 14088 KB Output is correct