답안 #1041978

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1041978 2024-08-02T11:33:54 Z Unforgettablepl Growing Vegetables is Fun 5 (JOI24_vegetables5) C++17
67 / 100
1566 ms 29060 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int INF = 1e13;

void strat1(int n) {
    vector<int> arr(2*n+1);
    for(int i=1;i<=2*n;i++)cin>>arr[i];
    vector<int> B(n);
    for(int&i:B)cin>>i;
    sort(B.begin(),B.end());
    vector<int> C(n);
    for(int&i:C)cin>>i;
    sort(C.begin(),C.end());
    int ans = INT64_MAX;
    for(int i=1;i<=n+1;i++){
        vector<int> pota,potb;
        for(int j=i;j<i+n;j++)pota.emplace_back(arr[j]);
        for(int j=1;j<i;j++)potb.emplace_back(arr[j]);
        for(int j=i+n;j<=2*n;j++)potb.emplace_back(arr[j]);
        sort(pota.begin(),pota.end());
        sort(potb.begin(),potb.end());
        {
            int myans = 0;
            for(int j=0;j<n;j++)myans=max(myans,abs(pota[j]-B[j]));
            for(int j=0;j<n;j++)myans=max(myans,abs(potb[j]-C[j]));
            ans=min(ans,myans);
        }
        swap(pota,potb);
        {
            int myans = 0;
            for(int j=0;j<n;j++)myans=max(myans,abs(pota[j]-B[j]));
            for(int j=0;j<n;j++)myans=max(myans,abs(potb[j]-C[j]));
            ans=min(ans,myans);
        }
    }
    cout << ans << '\n';
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    if(n<=2000){strat1(n);return 0;}
    vector<int> arr(2*n+1);
    for(int i=1;i<=2*n;i++)cin>>arr[i];
    vector<int> B(n);
    for(int&i:B)cin>>i;
    sort(B.begin(),B.end());
    vector<int> C(n);
    for(int&i:C)cin>>i;
    sort(C.begin(),C.end());
    auto check_support = [&](int x){
        // return a vector of bool of 1..n signifying if it works or not
        // check array against B
        vector<int> works(n+2);
        for(int i=1;i<=n;i++){
            auto it1 = lower_bound(B.begin(),B.end(),arr[i]-x);
            auto it2 = upper_bound(B.begin(),B.end(),arr[i]+x);
            if(it1==it2)continue;
            auto en = it1-B.begin();
            auto st = it2-B.begin()-1;
            works[max(i-st,1ll)]++;
            works[max(min(i-en+1,i+1),1ll)]--;
        }
        for(int i=n+1;i<2*n;i++){
            if(abs(arr[i]-B[2*n-i])>x)continue;
            works[i-n+1]++;
        }
        for(int i=1;i<=n;i++)works[i]+=works[i-1];
        vector<bool> res(n+1);
        for(int i=1;i<=n;i++)res[i]=works[i]==n;
        return res;
    };
    auto actcheck = [&](int x){
        auto t1 = check_support(x);
        swap(B,C);
        vector<int> newarr(2*n+1);
        for(int i=1;i<=n;i++)newarr[i+n]=arr[i];
        for(int i=n+1;i<=2*n;i++)newarr[i-n]=arr[i];
        for(int&i:B)i*=-1;
        for(int&i:newarr)i*=-1;
        reverse(B.begin(),B.end());
        swap(newarr,arr);
        auto t2 = check_support(x);
        swap(newarr,arr);
        reverse(B.begin(),B.end());
        for(int&i:B)i*=-1;
        swap(B,C);
        for(int i=1;i<=n;i++)if(t1[i] and t2[i])return true;
        return false;
    };
    auto check = [&](int x){
        if(actcheck(x))return true;
        swap(B,C);
        if(actcheck(x))return true;
        return false;
    };
    int ans = 0;
    for(int jump=536870912;jump;jump/=2){
        if(!check(jump+ans-1))ans+=jump;
    }
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 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 460 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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 460 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 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 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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 460 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 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 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 179 ms 604 KB Output is correct
27 Correct 165 ms 604 KB Output is correct
28 Correct 96 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 179 ms 604 KB Output is correct
31 Correct 159 ms 600 KB Output is correct
32 Correct 35 ms 344 KB Output is correct
33 Correct 8 ms 348 KB Output is correct
34 Correct 172 ms 604 KB Output is correct
35 Correct 183 ms 600 KB Output is correct
36 Correct 177 ms 628 KB Output is correct
37 Correct 67 ms 600 KB Output is correct
38 Correct 83 ms 604 KB Output is correct
39 Correct 98 ms 624 KB Output is correct
40 Correct 176 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1179 ms 28548 KB Output is correct
2 Correct 1045 ms 25064 KB Output is correct
3 Correct 816 ms 20836 KB Output is correct
4 Correct 1043 ms 28460 KB Output is correct
5 Correct 994 ms 25044 KB Output is correct
6 Correct 27 ms 1252 KB Output is correct
7 Correct 899 ms 29060 KB Output is correct
8 Correct 883 ms 23848 KB Output is correct
9 Correct 871 ms 28548 KB Output is correct
10 Correct 1140 ms 28424 KB Output is correct
11 Correct 1089 ms 28464 KB Output is correct
12 Correct 1016 ms 26120 KB Output is correct
13 Correct 1085 ms 25048 KB Output is correct
14 Correct 857 ms 28800 KB Output is correct
15 Correct 698 ms 24876 KB Output is correct
16 Correct 782 ms 24992 KB Output is correct
# 결과 실행 시간 메모리 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 460 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 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 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 179 ms 604 KB Output is correct
27 Correct 165 ms 604 KB Output is correct
28 Correct 96 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 179 ms 604 KB Output is correct
31 Correct 159 ms 600 KB Output is correct
32 Correct 35 ms 344 KB Output is correct
33 Correct 8 ms 348 KB Output is correct
34 Correct 172 ms 604 KB Output is correct
35 Correct 183 ms 600 KB Output is correct
36 Correct 177 ms 628 KB Output is correct
37 Correct 67 ms 600 KB Output is correct
38 Correct 83 ms 604 KB Output is correct
39 Correct 98 ms 624 KB Output is correct
40 Correct 176 ms 588 KB Output is correct
41 Correct 1179 ms 28548 KB Output is correct
42 Correct 1045 ms 25064 KB Output is correct
43 Correct 816 ms 20836 KB Output is correct
44 Correct 1043 ms 28460 KB Output is correct
45 Correct 994 ms 25044 KB Output is correct
46 Correct 27 ms 1252 KB Output is correct
47 Correct 899 ms 29060 KB Output is correct
48 Correct 883 ms 23848 KB Output is correct
49 Correct 871 ms 28548 KB Output is correct
50 Correct 1140 ms 28424 KB Output is correct
51 Correct 1089 ms 28464 KB Output is correct
52 Correct 1016 ms 26120 KB Output is correct
53 Correct 1085 ms 25048 KB Output is correct
54 Correct 857 ms 28800 KB Output is correct
55 Correct 698 ms 24876 KB Output is correct
56 Correct 782 ms 24992 KB Output is correct
57 Correct 1038 ms 28420 KB Output is correct
58 Correct 1018 ms 25048 KB Output is correct
59 Correct 566 ms 19052 KB Output is correct
60 Incorrect 1566 ms 28716 KB Output isn't correct
61 Halted 0 ms 0 KB -