Submission #922091

# Submission time Handle Problem Language Result Execution time Memory
922091 2024-02-05T02:31:02 Z guagua0407 Road Construction (JOI21_road_construction) C++17
100 / 100
1866 ms 14516 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#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({vec[r].s+d,inf});
        for(auto it=S.lower_bound({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;
}

signed 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: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 + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
road_construction.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 90 ms 5136 KB Output is correct
2 Correct 89 ms 5072 KB Output is correct
3 Correct 85 ms 5144 KB Output is correct
4 Correct 78 ms 5140 KB Output is correct
5 Correct 88 ms 4060 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 309 ms 9548 KB Output is correct
2 Correct 310 ms 9404 KB Output is correct
3 Correct 71 ms 5076 KB Output is correct
4 Correct 246 ms 11704 KB Output is correct
5 Correct 258 ms 12424 KB Output is correct
6 Correct 242 ms 11960 KB Output is correct
7 Correct 227 ms 11452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 5064 KB Output is correct
2 Correct 261 ms 6480 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 113 ms 5076 KB Output is correct
5 Correct 323 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 5064 KB Output is correct
2 Correct 261 ms 6480 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 113 ms 5076 KB Output is correct
5 Correct 323 ms 5072 KB Output is correct
6 Correct 393 ms 5524 KB Output is correct
7 Correct 355 ms 5580 KB Output is correct
8 Correct 0 ms 768 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 261 ms 8396 KB Output is correct
11 Correct 93 ms 6856 KB Output is correct
12 Correct 336 ms 8612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 5136 KB Output is correct
2 Correct 89 ms 5072 KB Output is correct
3 Correct 85 ms 5144 KB Output is correct
4 Correct 78 ms 5140 KB Output is correct
5 Correct 88 ms 4060 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 887 ms 7716 KB Output is correct
8 Correct 865 ms 7700 KB Output is correct
9 Correct 81 ms 5072 KB Output is correct
10 Correct 433 ms 7072 KB Output is correct
11 Correct 252 ms 6956 KB Output is correct
12 Correct 382 ms 7736 KB Output is correct
13 Correct 457 ms 7112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 5136 KB Output is correct
2 Correct 89 ms 5072 KB Output is correct
3 Correct 85 ms 5144 KB Output is correct
4 Correct 78 ms 5140 KB Output is correct
5 Correct 88 ms 4060 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 309 ms 9548 KB Output is correct
8 Correct 310 ms 9404 KB Output is correct
9 Correct 71 ms 5076 KB Output is correct
10 Correct 246 ms 11704 KB Output is correct
11 Correct 258 ms 12424 KB Output is correct
12 Correct 242 ms 11960 KB Output is correct
13 Correct 227 ms 11452 KB Output is correct
14 Correct 213 ms 5064 KB Output is correct
15 Correct 261 ms 6480 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 113 ms 5076 KB Output is correct
18 Correct 323 ms 5072 KB Output is correct
19 Correct 393 ms 5524 KB Output is correct
20 Correct 355 ms 5580 KB Output is correct
21 Correct 0 ms 768 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 261 ms 8396 KB Output is correct
24 Correct 93 ms 6856 KB Output is correct
25 Correct 336 ms 8612 KB Output is correct
26 Correct 887 ms 7716 KB Output is correct
27 Correct 865 ms 7700 KB Output is correct
28 Correct 81 ms 5072 KB Output is correct
29 Correct 433 ms 7072 KB Output is correct
30 Correct 252 ms 6956 KB Output is correct
31 Correct 382 ms 7736 KB Output is correct
32 Correct 457 ms 7112 KB Output is correct
33 Correct 1859 ms 14260 KB Output is correct
34 Correct 1866 ms 14260 KB Output is correct
35 Correct 1093 ms 13512 KB Output is correct
36 Correct 590 ms 14272 KB Output is correct
37 Correct 614 ms 14516 KB Output is correct
38 Correct 677 ms 12980 KB Output is correct