Submission #1041306

#TimeUsernameProblemLanguageResultExecution timeMemory
1041306UnforgettableplGrowing Vegetables is Fun 5 (JOI24_vegetables5)C++17
37 / 100
3048 ms35304 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int INF = 1e13; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> 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()); 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> rarr(2*n+1); for(int i=1;i<=2*n;i++)rarr[2*n-i+1]=arr[i]; 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; int breakpoint = lower_bound(rarr.begin()+1,rarr.begin()+1+n,arr[i])-rarr.begin(); breakpoint = n+2-breakpoint; st = max(i-st,1ll); en = max(min(i-en,i),0ll); if(breakpoint<st)continue; if(st<=breakpoint and breakpoint<=en)en = i; works[st]++; works[en+1]--; } for(int i=n+1;i<2*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 st = it1-B.begin(); auto en = it2-B.begin()-1; int breakpoint = upper_bound(arr.begin()+1,arr.begin()+n,arr[i])-arr.begin(); st = max(min(i+st-n,n+1),i-n+1); en = max(min(i+en-n,n),i-n); if(en<breakpoint)continue; if(st<=breakpoint and breakpoint<=en)st = i-n+1; works[st]++; works[en+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; }; check(0); int ans = 0; for(int jump=536870912;jump;jump/=2){ if(!check(jump+ans-1))ans+=jump; } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...