답안 #910821

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
910821 2024-01-18T08:19:10 Z Tuanlinh123 Road Construction (JOI21_road_construction) C++17
6 / 100
299 ms 10720 KB
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
using namespace std;

pll p[250005];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, k; cin >> n >> k;
    for (ll i=1; i<=n; i++)
    {
        ll x, y; cin >> x >> y;
        p[i]={x+y, x-y};
    }
    sort(p+1, p+n+1);
    vector <ll> ans;
    auto calc=[&](ll mid, bool trace)
    {
        set <pll> s;
        for (ll i=1, ptr=1, cnt=0; i<=n; i++)
        {
            while (ptr<i && p[ptr].fi<p[i].fi-mid)
                s.erase(mp(p[ptr].se, ptr)), ptr++;
            auto it=s.lower_bound(mp(p[i].se-mid, 0));
            while (it!=s.end() && (*it).fi<=p[i].se+mid)
            {
                if (++cnt>k) return 0;
                if (trace) ans.pb(max(abs(p[i].fi-p[(*it).se].fi), abs(p[i].se-p[(*it).se].se)));
                it++;
            }
            s.insert(mp(p[i].se, i));
        }
        return 1;
    };
    ll lo=0, hi=2e9;
    while (lo<hi)
    {
        ll mid=(lo+hi+1)/2;
        if (calc(mid, 0))
            lo=mid;
        else hi=mid-1;
    }
    calc(lo, 1);
    sort(ans.begin(), ans.end());
    while (ans.size()<k) ans.pb(lo+1);
    for (ll i:ans) cout << i << "\n";
}

Compilation message

road_construction.cpp: In function 'int main()':
road_construction.cpp:53:22: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   53 |     while (ans.size()<k) ans.pb(lo+1);
      |            ~~~~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 5064 KB Output is correct
2 Correct 76 ms 5068 KB Output is correct
3 Incorrect 61 ms 5072 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 294 ms 10720 KB Output is correct
2 Correct 299 ms 10640 KB Output is correct
3 Correct 63 ms 5248 KB Output is correct
4 Correct 229 ms 10344 KB Output is correct
5 Correct 265 ms 10468 KB Output is correct
6 Correct 260 ms 10640 KB Output is correct
7 Correct 228 ms 9980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 287 ms 9440 KB Output is correct
2 Correct 265 ms 9432 KB Output is correct
3 Incorrect 1 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 287 ms 9440 KB Output is correct
2 Correct 265 ms 9432 KB Output is correct
3 Incorrect 1 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 5064 KB Output is correct
2 Correct 76 ms 5068 KB Output is correct
3 Incorrect 61 ms 5072 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 5064 KB Output is correct
2 Correct 76 ms 5068 KB Output is correct
3 Incorrect 61 ms 5072 KB Output isn't correct
4 Halted 0 ms 0 KB -