Submission #1071115

# Submission time Handle Problem Language Result Execution time Memory
1071115 2024-08-23T04:55:25 Z ttamx Cultivation (JOI17_cultivation) C++17
30 / 100
871 ms 988 KB
#include<bits/stdc++.h>

using namespace std;

const int N=305;
const int INF=INT_MAX;

int n,r,c;
int x[N],y[N];

int calc(int xl,int xr){
    vector<int> xs;
    for(int i=0;i<n;i++){
        xs.emplace_back(max(1,x[i]-xl));
        xs.emplace_back(max(1,x[i]-xl-1));
        xs.emplace_back(min(r,x[i]+xr+1));
    }
    xs.emplace_back(1);
    xs.emplace_back(r);
    sort(xs.begin(),xs.end());
    xs.erase(unique(xs.begin(),xs.end()),xs.end());
    int xn=xs.size();
    vector<vector<pair<int,int>>> event(xn);
    for(int i=0;i<n;i++){
        int xi=lower_bound(xs.begin(),xs.end(),max(1,x[i]-xl))-xs.begin();
        int xj=upper_bound(xs.begin(),xs.end(),min(r,x[i]+xr))-xs.begin();
        event[xi].emplace_back(y[i],1);
        if(xj<xn){
            event[xj].emplace_back(y[i],0);
        }
    }
    int mxa=0,mxb=0,sum=0;
    multiset<int> pts,dif;
    for(auto &e:event){
        for(auto [x,t]:e){
            if(t){
                auto it=pts.emplace(x);
                if(next(it)!=pts.end()&&it!=pts.begin()){
                    dif.erase(dif.find(*next(it)-*prev(it)));
                }
                if(next(it)!=pts.end()){
                    dif.emplace(*next(it)-*it);
                }
                if(it!=pts.begin()){
                    dif.emplace(*it-*prev(it));
                }
            }else{
                auto it=pts.find(x);
                assert(it!=pts.end());
                if(next(it)!=pts.end()){
                    dif.erase(dif.find(*next(it)-*it));
                }
                if(it!=pts.begin()){
                    dif.erase(dif.find(*it-*prev(it)));
                }
                if(next(it)!=pts.end()&&it!=pts.begin()){
                    dif.emplace(*next(it)-*prev(it));
                }
                pts.erase(it);
            }
        }
        if(pts.empty())return INF;
        mxa=max(mxa,*pts.begin()-1);
        mxb=max(mxb,c-*pts.rbegin());
        if(!dif.empty()){
            sum=max(sum,*dif.rbegin()-1);
        }
    }
    return xl+xr+max(sum,mxa+mxb);
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> r >> c >> n;
    for(int i=0;i<n;i++){
        cin >> x[i] >> y[i];
    }
    vector<int> xs;
    for(int i=0;i<n;i++){
        xs.emplace_back(x[i]-1);
        xs.emplace_back(r-x[i]);
        for(int j=0;j<i;j++){
            int dx=abs(x[i]-x[j])-1;
            if(dx>=0)xs.emplace_back(dx);
        }
    }
    sort(xs.begin(),xs.end());
    xs.erase(unique(xs.begin(),xs.end()),xs.end());
    int ans=INF;
    for(int xl:xs){
        for(int xr:xs){
            ans=min(ans,calc(xl,xr));
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 13 ms 348 KB Output is correct
19 Correct 9 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 21 ms 480 KB Output is correct
22 Correct 74 ms 504 KB Output is correct
23 Correct 5 ms 348 KB Output is correct
24 Correct 129 ms 604 KB Output is correct
25 Correct 94 ms 544 KB Output is correct
26 Correct 212 ms 736 KB Output is correct
27 Correct 212 ms 732 KB Output is correct
28 Correct 132 ms 600 KB Output is correct
29 Correct 188 ms 736 KB Output is correct
30 Correct 207 ms 856 KB Output is correct
31 Correct 215 ms 856 KB Output is correct
32 Correct 206 ms 736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 13 ms 348 KB Output is correct
19 Correct 9 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 21 ms 480 KB Output is correct
22 Correct 74 ms 504 KB Output is correct
23 Correct 5 ms 348 KB Output is correct
24 Correct 129 ms 604 KB Output is correct
25 Correct 94 ms 544 KB Output is correct
26 Correct 212 ms 736 KB Output is correct
27 Correct 212 ms 732 KB Output is correct
28 Correct 132 ms 600 KB Output is correct
29 Correct 188 ms 736 KB Output is correct
30 Correct 207 ms 856 KB Output is correct
31 Correct 215 ms 856 KB Output is correct
32 Correct 206 ms 736 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 195 ms 736 KB Output is correct
35 Correct 216 ms 736 KB Output is correct
36 Correct 216 ms 860 KB Output is correct
37 Correct 175 ms 736 KB Output is correct
38 Correct 219 ms 732 KB Output is correct
39 Correct 242 ms 856 KB Output is correct
40 Correct 225 ms 736 KB Output is correct
41 Correct 179 ms 600 KB Output is correct
42 Correct 201 ms 736 KB Output is correct
43 Correct 216 ms 988 KB Output is correct
44 Correct 218 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 464 KB Output is correct
2 Correct 736 ms 704 KB Output is correct
3 Correct 868 ms 600 KB Output is correct
4 Incorrect 871 ms 452 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 98 ms 464 KB Output is correct
2 Correct 736 ms 704 KB Output is correct
3 Correct 868 ms 600 KB Output is correct
4 Incorrect 871 ms 452 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 13 ms 348 KB Output is correct
19 Correct 9 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 21 ms 480 KB Output is correct
22 Correct 74 ms 504 KB Output is correct
23 Correct 5 ms 348 KB Output is correct
24 Correct 129 ms 604 KB Output is correct
25 Correct 94 ms 544 KB Output is correct
26 Correct 212 ms 736 KB Output is correct
27 Correct 212 ms 732 KB Output is correct
28 Correct 132 ms 600 KB Output is correct
29 Correct 188 ms 736 KB Output is correct
30 Correct 207 ms 856 KB Output is correct
31 Correct 215 ms 856 KB Output is correct
32 Correct 206 ms 736 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 195 ms 736 KB Output is correct
35 Correct 216 ms 736 KB Output is correct
36 Correct 216 ms 860 KB Output is correct
37 Correct 175 ms 736 KB Output is correct
38 Correct 219 ms 732 KB Output is correct
39 Correct 242 ms 856 KB Output is correct
40 Correct 225 ms 736 KB Output is correct
41 Correct 179 ms 600 KB Output is correct
42 Correct 201 ms 736 KB Output is correct
43 Correct 216 ms 988 KB Output is correct
44 Correct 218 ms 856 KB Output is correct
45 Correct 98 ms 464 KB Output is correct
46 Correct 736 ms 704 KB Output is correct
47 Correct 868 ms 600 KB Output is correct
48 Incorrect 871 ms 452 KB Output isn't correct
49 Halted 0 ms 0 KB -