답안 #780326

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
780326 2023-07-12T08:18:00 Z Cookie Road Construction (JOI21_road_construction) C++14
7 / 100
305 ms 10596 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<int, int>>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 [candx, candy] = (*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:72:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   72 |             auto [candx, candy] = (*it);
      |                  ^
road_construction.cpp:85:23: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   85 |         cout << ans + 1 << "\n";
      |                       ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 68 ms 3340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 271 ms 10596 KB Output is correct
2 Correct 268 ms 10552 KB Output is correct
3 Incorrect 65 ms 4720 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 193 ms 9296 KB Output is correct
2 Correct 215 ms 9304 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 115 ms 7124 KB Output is correct
5 Correct 240 ms 9464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 193 ms 9296 KB Output is correct
2 Correct 215 ms 9304 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 115 ms 7124 KB Output is correct
5 Correct 240 ms 9464 KB Output is correct
6 Incorrect 305 ms 9304 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 68 ms 3340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 68 ms 3340 KB Output isn't correct
2 Halted 0 ms 0 KB -