답안 #1041055

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1041055 2024-08-01T14:25:14 Z alexdd Road Construction (JOI21_road_construction) C++17
100 / 100
1650 ms 19700 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 4e9;
int n,k;
pair<int,int> p[250005];
vector<int> sol;
int afis(int lim, bool bl)
{
    int poz=1,cnt=0;
    set<pair<int,int>> s;
    for(int i=1;i<=n;i++)
    {
        while(p[i].first-p[poz].first>lim)
        {
            s.erase({p[poz].second,p[poz].first});
            poz++;
        }
        for(auto it = s.lower_bound({p[i].second-lim,-INF});it!=s.upper_bound({p[i].second+lim,INF});it++)
        {
            if(bl) sol.push_back(max(abs(p[i].first-(*it).second),abs(p[i].second-(*it).first)));
            else cnt++;
            if(cnt==k)
                return k;
        }
        s.insert({p[i].second,p[i].first});
    }
    return cnt;
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>p[i].first>>p[i].second;
        p[i] = {p[i].first+p[i].second, p[i].first-p[i].second};
    }
    sort(p+1,p+1+n);
    int st=1,dr=INF,ans=INF;
    while(st<=dr)
    {
        int mij=(st+dr)/2;
        if(afis(mij,0)>=k)
        {
            ans=mij;
            dr=mij-1;
        }
        else
            st=mij+1;
    }
    afis(ans,1);
    sort(sol.begin(),sol.end());
    for(int i=0;i<k;i++)
        cout<<sol[i]<<"\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 4988 KB Output is correct
2 Correct 146 ms 5060 KB Output is correct
3 Correct 133 ms 5244 KB Output is correct
4 Correct 155 ms 5248 KB Output is correct
5 Correct 139 ms 4032 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 257 ms 7580 KB Output is correct
2 Correct 252 ms 9444 KB Output is correct
3 Correct 156 ms 5244 KB Output is correct
4 Correct 266 ms 12008 KB Output is correct
5 Correct 224 ms 13104 KB Output is correct
6 Correct 226 ms 12512 KB Output is correct
7 Correct 209 ms 12392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 137 ms 4188 KB Output is correct
2 Correct 188 ms 4176 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 104 ms 6524 KB Output is correct
5 Correct 222 ms 9176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 137 ms 4188 KB Output is correct
2 Correct 188 ms 4176 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 104 ms 6524 KB Output is correct
5 Correct 222 ms 9176 KB Output is correct
6 Correct 251 ms 4468 KB Output is correct
7 Correct 238 ms 4176 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 352 KB Output is correct
10 Correct 190 ms 4348 KB Output is correct
11 Correct 79 ms 6356 KB Output is correct
12 Correct 232 ms 4360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 4988 KB Output is correct
2 Correct 146 ms 5060 KB Output is correct
3 Correct 133 ms 5244 KB Output is correct
4 Correct 155 ms 5248 KB Output is correct
5 Correct 139 ms 4032 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 857 ms 6680 KB Output is correct
8 Correct 852 ms 6596 KB Output is correct
9 Correct 143 ms 5080 KB Output is correct
10 Correct 388 ms 6076 KB Output is correct
11 Correct 295 ms 7876 KB Output is correct
12 Correct 295 ms 10092 KB Output is correct
13 Correct 434 ms 10720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 4988 KB Output is correct
2 Correct 146 ms 5060 KB Output is correct
3 Correct 133 ms 5244 KB Output is correct
4 Correct 155 ms 5248 KB Output is correct
5 Correct 139 ms 4032 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 257 ms 7580 KB Output is correct
8 Correct 252 ms 9444 KB Output is correct
9 Correct 156 ms 5244 KB Output is correct
10 Correct 266 ms 12008 KB Output is correct
11 Correct 224 ms 13104 KB Output is correct
12 Correct 226 ms 12512 KB Output is correct
13 Correct 209 ms 12392 KB Output is correct
14 Correct 137 ms 4188 KB Output is correct
15 Correct 188 ms 4176 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 104 ms 6524 KB Output is correct
18 Correct 222 ms 9176 KB Output is correct
19 Correct 251 ms 4468 KB Output is correct
20 Correct 238 ms 4176 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 352 KB Output is correct
23 Correct 190 ms 4348 KB Output is correct
24 Correct 79 ms 6356 KB Output is correct
25 Correct 232 ms 4360 KB Output is correct
26 Correct 857 ms 6680 KB Output is correct
27 Correct 852 ms 6596 KB Output is correct
28 Correct 143 ms 5080 KB Output is correct
29 Correct 388 ms 6076 KB Output is correct
30 Correct 295 ms 7876 KB Output is correct
31 Correct 295 ms 10092 KB Output is correct
32 Correct 434 ms 10720 KB Output is correct
33 Correct 1650 ms 13444 KB Output is correct
34 Correct 1632 ms 13420 KB Output is correct
35 Correct 881 ms 12688 KB Output is correct
36 Correct 589 ms 19540 KB Output is correct
37 Correct 595 ms 19700 KB Output is correct
38 Correct 556 ms 14704 KB Output is correct