QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#420733 | #8645. Growing Vegetables is Fun 5 | Kevin5307 | 37 | 511ms | 31424kb | C++23 | 3.2kb | 2024-05-24 21:32:43 | 2024-05-24 21:32:45 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
ll A[600600],B[300300],C[300300];
ll psum[600600],psum2[600600];
ll delta[600600],delta2[600600];
int n;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n+n;i++)
cin>>A[i];
for(int i=1;i<=n;i++)
cin>>B[i];
for(int i=1;i<=n;i++)
cin>>C[i];
sort(B+1,B+n+1);
sort(C+1,C+n+1);
ll ans=0x3f3f3f3f3f3f3f3f;
{
for(int i=1;i<=n;i++)
psum[i]=max(psum[i-1],abs(C[i]-A[i]));
for(int i=n+1;i<=n+n;i++)
psum2[i]=max(psum2[i-1],abs(B[n+n+1-i]-A[i]));
ll l=0,r=1e9;
while(l<r)
{
memset(delta,0,sizeof(delta));
memset(delta2,0,sizeof(delta2));
ll mid=(l+r)/2;
int p1=1,p2=0;
bool flag=0;
for(int i=1;i<=n;i++)
{
while(p1<=n&&A[p1]<B[i]-mid)
p1++;
while(p2<n&&A[p2+1]<=B[i]+mid)
p2++;
if(p1<=p2)
{
delta[max(1,p1-i+1)]++;
delta[p2-i+2]--;
}
}
p1=n+n+1,p2=n+n;
for(int i=1;i<=n;i++)
{
while(p1>n+1&&A[p1-1]<=C[i]+mid)
p1--;
while(p2>n&&A[p2]<C[i]-mid)
p2--;
if(p1<=p2)
{
delta2[p1+i-n]++;
delta2[p2+i+1-n]--;
}
}
for(int i=1;i<=n+n;i++)
delta2[i]+=delta2[i-1];
for(int i=1;i<=n+n;i++)
delta[i]+=delta[i-1];
for(int i=0;i<=n;i++)
if(delta[n-i+1]==i&&psum2[n+n-i]<=mid&&psum[n-i]<=mid&&delta2[n+n-i+1]==i)
flag=1;
if(flag)
r=mid;
else
l=mid+1;
}
ans=min(ans,l);
}
for(int i=1;i<=n;i++)
swap(B[i],C[i]);
{
for(int i=1;i<=n;i++)
psum[i]=max(psum[i-1],abs(C[i]-A[i]));
for(int i=n+1;i<=n+n;i++)
psum2[i]=max(psum2[i-1],abs(B[n+n+1-i]-A[i]));
ll l=0,r=1e9;
while(l<r)
{
memset(delta,0,sizeof(delta));
memset(delta2,0,sizeof(delta2));
ll mid=(l+r)/2;
int p1=1,p2=0;
bool flag=0;
for(int i=1;i<=n;i++)
{
while(p1<=n&&A[p1]<B[i]-mid)
p1++;
while(p2<n&&A[p2+1]<=B[i]+mid)
p2++;
if(p1<=p2)
{
delta[max(1,p1-i+1)]++;
delta[p2-i+2]--;
}
}
p1=n+n+1,p2=n+n;
for(int i=1;i<=n;i++)
{
while(p1>n+1&&A[p1-1]<=C[i]+mid)
p1--;
while(p2>n&&A[p2]<C[i]-mid)
p2--;
if(p1<=p2)
{
delta2[p1+i-n]++;
delta2[p2+i+1-n]--;
}
}
for(int i=1;i<=n+n;i++)
delta2[i]+=delta2[i-1];
for(int i=1;i<=n+n;i++)
delta[i]+=delta[i-1];
for(int i=0;i<=n;i++)
if(delta[n-i+1]==i&&psum2[n+n-i]<=mid&&psum[n-i]<=mid&&delta2[n+n-i+1]==i)
flag=1;
if(flag)
r=mid;
else
l=mid+1;
}
ans=min(ans,l);
}
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 4
Accepted
time: 20ms
memory: 19148kb
input:
5 71039844 102827355 217531548 220229557 237972610 314010999 309303025 282414480 227324750 127910276 355992665 573821998 974848115 193721993 786455947 602158296 281786121 321727541 140763116 455641294
output:
660837116
result:
ok single line: '660837116'
Test #2:
score: 0
Accepted
time: 19ms
memory: 19172kb
input:
4 1705 9199 9245 9297 9785 8486 3596 2031 356 2834 9555 4667 1881 4772 9778 4863
output:
4427
result:
ok single line: '4427'
Test #3:
score: 0
Accepted
time: 23ms
memory: 19108kb
input:
3 1 1 1 1 1 1 6 4 7 4 2 6
output:
6
result:
ok single line: '6'
Test #4:
score: 0
Accepted
time: 19ms
memory: 19156kb
input:
2 2 2 10 6 9 2 9 2
output:
3
result:
ok single line: '3'
Test #5:
score: 0
Accepted
time: 20ms
memory: 19084kb
input:
1 349142605 778700270 168051580 502698453
output:
276001817
result:
ok single line: '276001817'
Test #6:
score: 0
Accepted
time: 19ms
memory: 19108kb
input:
5 17 17 18 18 19 20 19 19 18 17 16 21 17 15 22 16 15 12 17 19
output:
5
result:
ok single line: '5'
Test #7:
score: 0
Accepted
time: 23ms
memory: 19172kb
input:
5 4 7 8 8 9 9 8 5 5 4 8 5 6 6 9 7 7 8 1 7
output:
3
result:
ok single line: '3'
Test #8:
score: 0
Accepted
time: 19ms
memory: 19244kb
input:
4 6 7 8 8 10 10 8 7 10 9 4 6 6 6 8 7
output:
2
result:
ok single line: '2'
Test #9:
score: 0
Accepted
time: 23ms
memory: 19176kb
input:
5 1 285389468 292069311 556395360 725450787 931668868 448264980 368730609 214990111 201747487 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
output:
999999999
result:
ok single line: '999999999'
Test #10:
score: 0
Accepted
time: 23ms
memory: 19176kb
input:
5 662886918 684753078 783767220 920694140 923464013 1000000000 885337163 779952619 739901312 687764518 1 1 1 1 1 1 1 1 1 1
output:
999999999
result:
ok single line: '999999999'
Test #11:
score: 0
Accepted
time: 19ms
memory: 19236kb
input:
5 463408857 467609229 473997928 477395329 481525188 519068288 507259005 493795251 483097019 477045791 467609229 481525188 463408857 477395329 473997928 483097019 493795251 507259005 519068288 477045791
output:
0
result:
ok single line: '0'
Test #12:
score: -4
Wrong Answer
time: 19ms
memory: 19092kb
input:
3 1 3 5 6 4 2 2 3 4 5 6 7
output:
2
result:
wrong answer 1st lines differ - expected: '1', found: '2'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 37
Accepted
Test #41:
score: 37
Accepted
time: 511ms
memory: 30100kb
input:
300000 619 2319 3493 3715 4353 4926 8022 14367 18919 23666 25565 25582 27245 27303 28880 29568 29918 31815 34986 36861 40022 40147 47041 52120 55624 57816 58553 59319 60056 63512 66442 68907 68915 69471 69714 71129 76758 76761 77220 78196 84558 87950 88697 88782 89810 90113 92091 95040 97273 99148 1...
output:
167936427
result:
ok single line: '167936427'
Test #42:
score: 0
Accepted
time: 406ms
memory: 30880kb
input:
299999 2 3 4 7 8 9 13 16 17 18 20 22 24 25 30 31 32 33 34 35 36 39 40 41 42 45 49 50 57 59 61 62 63 64 65 66 67 68 71 72 77 79 80 84 85 89 90 92 93 95 96 99 100 103 104 105 108 110 113 117 118 119 122 123 126 127 130 131 132 133 134 135 140 143 146 148 151 152 153 154 155 158 160 161 164 168 169 173...
output:
167225
result:
ok single line: '167225'
Test #43:
score: 0
Accepted
time: 338ms
memory: 26916kb
input:
250000 1 2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 37 39 40 41 42 44 47 48 49 50 52 53 54 55 56 57 59 60 61 63 64 65 66 67 68 69 70 72 73 74 75 76 77 78 80 81 82 83 84 86 87 88 89 90 91 92 95 96 97 98 99 100 101 102 103 104 105 106 107 109 110 112 113 114 1...
output:
100064
result:
ok single line: '100064'
Test #44:
score: 0
Accepted
time: 504ms
memory: 31424kb
input:
300000 23 1084 4990 10033 10275 11917 12338 13780 18890 21272 21287 21541 21896 22307 22962 22994 28256 30306 35312 35789 37839 38480 40782 42608 43133 44514 46423 48426 50048 50896 51222 52721 53509 54878 56681 57093 58204 58476 58661 60138 66569 67553 68133 69448 71250 71855 72194 74345 74986 7503...
output:
26693
result:
ok single line: '26693'
Test #45:
score: 0
Accepted
time: 402ms
memory: 31192kb
input:
299998 2 3 4 5 7 9 10 12 14 15 17 19 20 24 28 30 31 32 33 35 36 41 43 44 45 46 47 48 50 51 53 54 57 58 60 61 62 63 66 67 68 69 71 72 73 74 75 77 80 81 83 84 88 90 94 96 97 99 100 101 102 104 105 106 108 110 111 113 115 117 119 120 122 123 124 125 126 127 128 130 131 132 133 134 135 136 137 138 140 1...
output:
982
result:
ok single line: '982'
Test #46:
score: 0
Accepted
time: 35ms
memory: 19272kb
input:
10000 13 34 36 45 54 59 60 62 70 73 84 85 87 89 93 95 100 101 102 104 107 110 114 115 118 128 131 132 140 143 144 147 150 151 152 154 160 164 168 183 187 190 195 196 215 217 222 237 241 251 252 256 257 262 268 269 279 285 290 293 298 299 303 304 312 313 316 323 328 329 330 331 336 342 347 351 352 35...
output:
285
result:
ok single line: '285'
Test #47:
score: 0
Accepted
time: 246ms
memory: 28572kb
input:
300000 1 473 3697 6630 7286 7657 9952 10287 11421 11877 12279 22156 29205 29365 29728 32757 33840 34011 34035 34229 35784 38558 39120 39894 40570 45844 46178 46806 51591 51960 55120 56505 59846 61666 65606 65795 67810 70418 70673 73000 76935 79219 79828 80316 80379 81725 83712 85781 88372 88526 8906...
output:
999999999
result:
ok single line: '999999999'
Test #48:
score: 0
Accepted
time: 212ms
memory: 29836kb
input:
300000 1295 1895 2725 3380 3426 7383 7395 8653 8775 13383 16038 21381 23341 24361 29918 30428 31274 31780 32932 33929 34648 35318 36424 39153 40615 42732 43263 44253 44641 45150 45181 47584 48740 48776 52807 53912 53981 54890 55260 57440 57974 60067 60378 62706 63469 65268 66129 66349 70951 71022 71...
output:
999999999
result:
ok single line: '999999999'
Test #49:
score: 0
Accepted
time: 488ms
memory: 31360kb
input:
300000 2915 7306 9074 9545 11829 14083 15092 15987 19985 21298 22831 24072 24289 25200 27940 29326 30028 31704 32095 33067 38446 39400 39983 41100 41956 42126 46127 46132 47577 49880 50711 52104 52900 54116 55805 57277 59116 62357 65455 66036 68185 71566 74707 75419 77086 82585 83076 85456 86516 945...
output:
0
result:
ok single line: '0'
Test #50:
score: 0
Accepted
time: 505ms
memory: 31180kb
input:
300000 3734 4059 4299 8744 9042 11200 11942 14293 15399 15809 18600 21612 25564 25979 27179 29385 31106 35067 36441 36869 41081 42148 43026 43398 46160 46622 50163 51319 51961 52012 59052 61212 61512 63247 65689 67224 67859 68268 69723 70709 71556 71624 71894 73600 74439 75304 75549 76030 80615 8115...
output:
100007
result:
ok single line: '100007'
Test #51:
score: 0
Accepted
time: 505ms
memory: 31100kb
input:
299998 432 1412 4873 6571 7309 12551 12734 14732 15371 15438 15548 17297 18854 20451 20775 21337 21678 25482 26393 27023 27624 29195 30972 31555 32520 32897 32939 33759 36460 37924 39012 40803 42086 42848 44784 46053 47197 49089 49218 49887 53402 54204 54956 55068 55685 56929 58263 59160 60732 60891...
output:
100007
result:
ok single line: '100007'
Test #52:
score: 0
Accepted
time: 446ms
memory: 30012kb
input:
300000 6 47 48 73 77 80 84 92 97 110 121 126 206 210 226 243 245 247 249 250 269 298 301 305 308 319 320 348 363 375 379 401 404 475 492 496 539 540 544 559 568 589 598 629 650 669 674 702 726 734 775 776 803 805 828 834 855 887 903 904 907 985 986 1005 1038 1068 1075 1082 1084 1092 1131 1136 1157 1...
output:
100007
result:
ok single line: '100007'
Test #53:
score: 0
Accepted
time: 398ms
memory: 28504kb
input:
300000 1 2 3 6 9 11 13 14 19 20 23 25 26 27 28 30 31 33 34 36 38 39 40 42 43 44 45 46 47 48 49 50 51 52 53 57 58 59 61 63 64 66 68 69 72 73 74 75 76 78 79 80 81 82 84 86 87 88 89 90 91 92 93 95 99 101 102 104 105 106 110 112 114 115 121 122 123 128 129 131 132 133 134 136 138 139 140 142 143 144 146...
output:
100007
result:
ok single line: '100007'
Test #54:
score: 0
Accepted
time: 257ms
memory: 31128kb
input:
300000 417 4951 13971 15437 15471 15664 17651 21576 23240 25724 28611 28771 30770 30798 31848 33007 36175 36934 37324 39752 40791 41422 41592 42971 44539 45026 46702 48168 51631 56662 57901 58708 60804 63166 63192 65791 67031 67106 67883 68505 70865 71954 74368 74787 75235 75324 76773 78080 78122 78...
output:
192337248
result:
ok single line: '192337248'
Test #55:
score: 0
Accepted
time: 236ms
memory: 29552kb
input:
300000 1 2 3 4 5 6 7 10 11 12 13 14 15 17 18 20 21 22 23 26 31 33 34 37 39 41 45 47 48 49 50 51 53 54 55 56 58 59 60 61 62 65 66 67 73 75 77 78 79 81 82 83 85 88 89 91 97 98 100 101 102 103 104 107 108 111 112 113 114 115 116 118 119 120 123 126 131 133 134 135 136 138 139 140 141 144 145 147 149 15...
output:
301854
result:
ok single line: '301854'
Test #56:
score: 0
Accepted
time: 240ms
memory: 29984kb
input:
300000 1 2 3 4 5 6 7 8 9 12 21 22 23 25 27 28 32 36 37 38 40 42 43 45 48 49 50 53 54 55 58 59 60 61 62 63 64 68 69 71 74 76 77 79 80 81 82 84 86 89 91 93 95 96 97 98 99 100 101 102 103 104 105 108 110 112 113 114 115 116 117 118 120 122 123 124 125 126 128 131 133 134 136 139 140 142 144 145 146 147...
output:
273966
result:
ok single line: '273966'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%