Submission #922092

# Submission time Handle Problem Language Result Execution time Memory
922092 2024-02-05T02:32:16 Z guagua0407 Road Construction (JOI21_road_construction) C++17
100 / 100
1858 ms 6320 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

const int inf=2e9+5;
int n,k;
vector<pair<int,int>> vec;
vector<ll> ans;

bool check(ll d){
    int l=0;
    set<pair<int,int>> S;
    ans.clear();
    for(int r=0;r<n;r++){
        while(vec[l].f<max(-(ll)inf,(ll)vec[r].f-d)){
            S.erase({vec[l].s,l});
            l++;
        }
        auto it2=S.upper_bound({min((ll)inf,(ll)vec[r].s+d),inf});
        for(auto it=S.lower_bound({max(-(ll)inf,(ll)vec[r].s-d),-inf});it!=it2;it++){
            int x=(*it).s;
            ans.push_back(max(abs((ll)vec[x].f-(ll)vec[r].f),abs((ll)vec[x].s-(ll)vec[r].s)));
            if((int)ans.size()>=k) return true;
        }
        S.insert({vec[r].s,r});
    }
    return false;
}

int main() {_
    cin>>n>>k;
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        int xx=y+x;
        int yy=y-x;
        vec.push_back({xx,yy});
    }
    sort(all(vec));
    ll l=0,r=(ll)4e9;
    while(l<r){
        ll mid=(l+r)/2;
        if(check(mid)){
            r=mid;
        }
        else{
            l=mid+1;
        }
    }
    check(l-1);
    sort(all(ans));
    while((int)ans.size()<k) ans.push_back(l);
    for(auto v:ans){
        cout<<v<<'\n';
    }
    return 0;
}
//maybe its multiset not set
//yeeorz
//laborz

Compilation message

road_construction.cpp: In function 'void setIO(std::string)':
road_construction.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
road_construction.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 87 ms 5112 KB Output is correct
2 Correct 85 ms 5064 KB Output is correct
3 Correct 83 ms 5068 KB Output is correct
4 Correct 80 ms 5120 KB Output is correct
5 Correct 81 ms 3784 KB Output is correct
6 Correct 3 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 318 ms 5728 KB Output is correct
2 Correct 311 ms 5728 KB Output is correct
3 Correct 77 ms 4848 KB Output is correct
4 Correct 244 ms 5468 KB Output is correct
5 Correct 254 ms 5760 KB Output is correct
6 Correct 265 ms 5572 KB Output is correct
7 Correct 222 ms 5272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 197 ms 2556 KB Output is correct
2 Correct 257 ms 2508 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 150 ms 2520 KB Output is correct
5 Correct 309 ms 2524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 197 ms 2556 KB Output is correct
2 Correct 257 ms 2508 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 150 ms 2520 KB Output is correct
5 Correct 309 ms 2524 KB Output is correct
6 Correct 390 ms 2512 KB Output is correct
7 Correct 348 ms 2648 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 269 ms 2512 KB Output is correct
11 Correct 93 ms 2516 KB Output is correct
12 Correct 310 ms 2516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 5112 KB Output is correct
2 Correct 85 ms 5064 KB Output is correct
3 Correct 83 ms 5068 KB Output is correct
4 Correct 80 ms 5120 KB Output is correct
5 Correct 81 ms 3784 KB Output is correct
6 Correct 3 ms 344 KB Output is correct
7 Correct 851 ms 5128 KB Output is correct
8 Correct 857 ms 5132 KB Output is correct
9 Correct 84 ms 5120 KB Output is correct
10 Correct 412 ms 4620 KB Output is correct
11 Correct 267 ms 4364 KB Output is correct
12 Correct 349 ms 5140 KB Output is correct
13 Correct 442 ms 3592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 5112 KB Output is correct
2 Correct 85 ms 5064 KB Output is correct
3 Correct 83 ms 5068 KB Output is correct
4 Correct 80 ms 5120 KB Output is correct
5 Correct 81 ms 3784 KB Output is correct
6 Correct 3 ms 344 KB Output is correct
7 Correct 318 ms 5728 KB Output is correct
8 Correct 311 ms 5728 KB Output is correct
9 Correct 77 ms 4848 KB Output is correct
10 Correct 244 ms 5468 KB Output is correct
11 Correct 254 ms 5760 KB Output is correct
12 Correct 265 ms 5572 KB Output is correct
13 Correct 222 ms 5272 KB Output is correct
14 Correct 197 ms 2556 KB Output is correct
15 Correct 257 ms 2508 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 150 ms 2520 KB Output is correct
18 Correct 309 ms 2524 KB Output is correct
19 Correct 390 ms 2512 KB Output is correct
20 Correct 348 ms 2648 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 269 ms 2512 KB Output is correct
24 Correct 93 ms 2516 KB Output is correct
25 Correct 310 ms 2516 KB Output is correct
26 Correct 851 ms 5128 KB Output is correct
27 Correct 857 ms 5132 KB Output is correct
28 Correct 84 ms 5120 KB Output is correct
29 Correct 412 ms 4620 KB Output is correct
30 Correct 267 ms 4364 KB Output is correct
31 Correct 349 ms 5140 KB Output is correct
32 Correct 442 ms 3592 KB Output is correct
33 Correct 1858 ms 6312 KB Output is correct
34 Correct 1828 ms 6312 KB Output is correct
35 Correct 1115 ms 5728 KB Output is correct
36 Correct 593 ms 6244 KB Output is correct
37 Correct 619 ms 6320 KB Output is correct
38 Correct 640 ms 5316 KB Output is correct