Submission #780341

# Submission time Handle Problem Language Result Execution time Memory
780341 2023-07-12T08:22:24 Z Cookie Road Construction (JOI21_road_construction) C++14
100 / 100
1252 ms 13412 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("VNOICUP.INP");
ofstream fout("VNOICUP.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
//const int y[4] = {0, 0, 1, -1};
const ll mod = 998244353;
const int mxn = 25e4 + 5, mxq = 2e5 + 5, sq = 400, mxv = 2e7 + 5;
//const int base = (1 << 18);
const ll inf = 1e9 + 5, neg = -69420;
int n, k;
pll p[mxn + 1];
bool ck(ll mid){
    multiset<ll>ms;
    int l = 1, cnt = 0;
    for(int i = 1; i <= n; i++){
        while(p[i].fi - p[l].fi > mid){
            ms.erase(ms.find(p[l].se)); l++;
        }
        auto it = ms.lower_bound(p[i].se - mid);
        for(;it != ms.end(); ++it){
            if((*it) > p[i].se + mid)break;
            cnt++;
            if(cnt > k)return(0);
        }
        ms.insert(p[i].se);
    }
    return(1);
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        int x, y; cin >> x >> y;
        p[i] = make_pair(x + y, x - y);
    }
    sort(p + 1, p + n + 1);
    ll l = 0, r = 4e9, ans;
    while(l <= r){
        ll mid = (l + r) >> 1;
        if(ck(mid)){
            ans = mid; l = mid + 1;
        }else{
            r = mid - 1;
        }
    }
 
    set<pair<ll, ll>>s;
    vt<ll>res;
    int lp = 1;
    for(int i = 1; i <= n; i++){
        while(p[i].fi - p[lp].fi > ans){
            
            s.erase(make_pair(p[lp].se, p[lp].fi)); lp++;
        }
        auto it = s.lower_bound(make_pair(p[i].se - ans, -inf));
        for(;it != s.end(); ++it){
            
            auto [candy, candx] = (*it);
            ll dist = max(p[i].fi - candx, abs(p[i].se - candy));

            if(dist <= ans){
                res.pb(dist); 
            }else{
                break;
            }
        }
        s.insert(make_pair(p[i].se, p[i].fi));
    }
    
    sort(res.begin(), res.end());
    for(auto i: res)cout << i << "\n";
    forr(i, 0, k - sz(res)){
        cout << ans + 1 << "\n";
    }
    return(0);
}

Compilation message

road_construction.cpp: In function 'int main()':
road_construction.cpp:74:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   74 |             auto [candy, candx] = (*it);
      |                  ^
road_construction.cpp:89:23: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   89 |         cout << ans + 1 << "\n";
      |                       ^
# Verdict Execution time Memory Grader output
1 Correct 71 ms 4976 KB Output is correct
2 Correct 71 ms 4996 KB Output is correct
3 Correct 64 ms 5096 KB Output is correct
4 Correct 62 ms 5112 KB Output is correct
5 Correct 72 ms 3892 KB Output is correct
6 Correct 2 ms 360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 271 ms 7560 KB Output is correct
2 Correct 269 ms 7504 KB Output is correct
3 Correct 58 ms 4936 KB Output is correct
4 Correct 234 ms 10308 KB Output is correct
5 Correct 207 ms 10500 KB Output is correct
6 Correct 198 ms 10600 KB Output is correct
7 Correct 187 ms 9940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 229 ms 4224 KB Output is correct
2 Correct 223 ms 4220 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 112 ms 4188 KB Output is correct
5 Correct 237 ms 4248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 229 ms 4224 KB Output is correct
2 Correct 223 ms 4220 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 112 ms 4188 KB Output is correct
5 Correct 237 ms 4248 KB Output is correct
6 Correct 311 ms 4220 KB Output is correct
7 Correct 288 ms 9304 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 250 ms 9300 KB Output is correct
11 Correct 98 ms 7160 KB Output is correct
12 Correct 237 ms 9548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 4976 KB Output is correct
2 Correct 71 ms 4996 KB Output is correct
3 Correct 64 ms 5096 KB Output is correct
4 Correct 62 ms 5112 KB Output is correct
5 Correct 72 ms 3892 KB Output is correct
6 Correct 2 ms 360 KB Output is correct
7 Correct 581 ms 8032 KB Output is correct
8 Correct 576 ms 8032 KB Output is correct
9 Correct 67 ms 5152 KB Output is correct
10 Correct 329 ms 7308 KB Output is correct
11 Correct 206 ms 7268 KB Output is correct
12 Correct 212 ms 5960 KB Output is correct
13 Correct 300 ms 6624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 4976 KB Output is correct
2 Correct 71 ms 4996 KB Output is correct
3 Correct 64 ms 5096 KB Output is correct
4 Correct 62 ms 5112 KB Output is correct
5 Correct 72 ms 3892 KB Output is correct
6 Correct 2 ms 360 KB Output is correct
7 Correct 271 ms 7560 KB Output is correct
8 Correct 269 ms 7504 KB Output is correct
9 Correct 58 ms 4936 KB Output is correct
10 Correct 234 ms 10308 KB Output is correct
11 Correct 207 ms 10500 KB Output is correct
12 Correct 198 ms 10600 KB Output is correct
13 Correct 187 ms 9940 KB Output is correct
14 Correct 229 ms 4224 KB Output is correct
15 Correct 223 ms 4220 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 112 ms 4188 KB Output is correct
18 Correct 237 ms 4248 KB Output is correct
19 Correct 311 ms 4220 KB Output is correct
20 Correct 288 ms 9304 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 250 ms 9300 KB Output is correct
24 Correct 98 ms 7160 KB Output is correct
25 Correct 237 ms 9548 KB Output is correct
26 Correct 581 ms 8032 KB Output is correct
27 Correct 576 ms 8032 KB Output is correct
28 Correct 67 ms 5152 KB Output is correct
29 Correct 329 ms 7308 KB Output is correct
30 Correct 206 ms 7268 KB Output is correct
31 Correct 212 ms 5960 KB Output is correct
32 Correct 300 ms 6624 KB Output is correct
33 Correct 1252 ms 13412 KB Output is correct
34 Correct 1174 ms 13412 KB Output is correct
35 Correct 829 ms 12644 KB Output is correct
36 Correct 394 ms 11520 KB Output is correct
37 Correct 383 ms 11420 KB Output is correct
38 Correct 466 ms 12104 KB Output is correct