QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#201560 | #1959. John's Gift | std_abs# | AC ✓ | 272ms | 33212kb | C++17 | 2.0kb | 2023-10-05 15:09:15 | 2023-10-05 15:09:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) ((int)a.size())
const int N = 100005;
typedef pair<int, int> pi;
vector<int> f(vector<int> a, vector<int> b) {
int n = b.size();
vector<int> l(n), r(n + 1), res(n + 1);
if (n == 0) {
return vector<int>(1, 0);
}
for (int i = 0; i < n; ++i)
l[i] = max((i ? l[i - 1] : 0), abs(a[i] - b[i]));
for (int i = n; i; --i)
r[i] = max(i < n ? r[i + 1] : 0, abs(a[i] - b[i - 1]));
for (int i = 1; i < n; ++i)
res[i] = max(l[i - 1], r[i + 1]);
res[0] = r[1], res[n] = l[n - 1];
return res;
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
vector<int> a(n), b(n);
for (int &i : a)
cin >> i;
for (int &i : b)
cin >> i;
sort(all(a)), sort(all(b));
int x = 0;
for (int i = 1; i < n; ++i)
if (abs(a[i] - b[i]) > abs(a[x] - b[x]))
x = i;
vector<int> mn(n, 1e9);
mn[0] = 0;
for (int i = 0; i < n; ++i)
if (i != 0)
mn[0] = max(mn[0], abs(a[i] - b[i]));
{
vector<int> tmp = f(vector<int>(b.begin(), b.begin() + x + 1), vector<int>(a.begin(), a.begin() + x));
vector<int> tmp2 = f(vector<int>(a.begin() + x, a.end()), vector<int>(b.begin() + x + 1, b.end()));
int mx = *min_element(all(tmp));
for (int i = x; i < n; ++i)
mn[i] = min(mn[i], max(tmp2[i - x], mx));
}
{
vector<int> tmp = f(vector<int>(a.begin(), a.begin() + x + 1), vector<int>(b.begin(), b.begin() + x));
vector<int> tmp2 = f(vector<int>(b.begin() + x, b.end()), vector<int>(a.begin() + x + 1, a.end()));
int mx = *min_element(all(tmp2));
for (int i = 0; i <= x; ++i)
mn[i] = min(mn[i], max(tmp[i], mx));
}
x = 0;
for (int i = 0; i < n; ++i)
if (mn[i] < mn[x])
x = i;
cout << a[x] << '\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3548kb
input:
2 10 30 10 20
output:
30
result:
ok single line: '30'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3528kb
input:
3 20 30 40 30 20 10
output:
40
result:
ok single line: '40'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3448kb
input:
4 24 68 51 10 20 30 40 50
output:
68
result:
ok single line: '68'
Test #4:
score: 0
Accepted
time: 20ms
memory: 6228kb
input:
100000 4127 27398 25263 12138 63055 50544 62602 61804 24966 95177 35325 68178 18062 99863 19505 3729 22567 2644 53741 27078 95179 53087 21654 88680 48240 20014 19310 72776 14842 24861 28386 24316 26613 20800 77885 43815 62309 13002 69925 39150 35779 20230 93290 12019 76404 42524 75212 91370 94723 33...
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 19ms
memory: 6240kb
input:
100000 996675845 199970752 440700615 664782273 957861408 572353051 584740807 202580072 72278511 944508055 394000228 514035495 365806826 355900733 341840104 820949562 137526375 753473403 928297004 234121586 542392933 10424061 709380466 448037576 758321098 886308147 228431573 20472921 923837046 605733...
output:
1803
result:
ok single line: '1803'
Test #6:
score: 0
Accepted
time: 27ms
memory: 6248kb
input:
100000 99043753 850464060 448433178 139220288 807223553 269501877 397929892 746695929 919965808 962728020 269339347 573929066 74819082 724793915 599324395 277091379 562386490 108614945 973105494 67515926 316636395 530456710 103230230 557680196 759909626 942049121 664851300 760495786 34970461 4168717...
output:
25624
result:
ok single line: '25624'
Test #7:
score: 0
Accepted
time: 16ms
memory: 6256kb
input:
100000 479590992 195794301 300796492 995421850 768741542 160051469 430390564 110057352 353836341 895601617 84922251 168860941 676679654 926882491 478596553 813923681 36358550 219873128 240305986 76337549 693367343 253214186 384110168 894016405 536291829 257059815 688988035 671219201 261583084 295514...
output:
17281
result:
ok single line: '17281'
Test #8:
score: 0
Accepted
time: 23ms
memory: 5440kb
input:
100000 393760535 802574479 463560720 994414183 396195155 854837150 665550765 685020414 52187094 218080555 997844270 551940728 476095356 767031048 218723436 936233629 666025245 194974468 912871690 254608509 776172825 521905067 798887617 856190599 490225545 785778856 65177375 327624550 50094554 485323...
output:
30968
result:
ok single line: '30968'
Test #9:
score: 0
Accepted
time: 23ms
memory: 5440kb
input:
100000 339129759 238503399 884979123 474643832 850181558 306199789 500973470 770176828 979622587 9868709 651597323 934348903 960838225 904969411 761959662 408961338 218401474 421756293 358858013 74095844 341315040 839189889 885471294 906418465 676266398 898901100 935191403 45648341 266598713 5221561...
output:
3016
result:
ok single line: '3016'
Test #10:
score: 0
Accepted
time: 27ms
memory: 6188kb
input:
100000 866128867 320680200 137564371 870100992 154049742 336889732 403261068 976034141 942165991 450569705 129070806 165265879 372161649 310801797 926999305 198605170 99284902 729873100 557354939 505127757 516313315 93689900 648346034 274995836 660706353 802181010 724215716 281732993 552419576 82288...
output:
14068
result:
ok single line: '14068'
Test #11:
score: 0
Accepted
time: 24ms
memory: 5360kb
input:
100000 511785115 941891987 811220533 963951203 838322235 162138871 668805276 744139032 962261816 764764854 619014099 700994182 938106333 927697607 394973440 106156802 376475384 175368687 222790261 818051193 459269631 136448123 461439904 71964360 330065209 692991330 120389062 174634138 597317803 8493...
output:
3881
result:
ok single line: '3881'
Test #12:
score: 0
Accepted
time: 27ms
memory: 6204kb
input:
100000 34902963 21770539 63196119 98371385 76600357 94791470 99420697 56047981 43722286 59237254 59872719 17753279 50940126 55948709 89857740 6846533 72016769 35177624 76094134 21991357 71263081 85212435 46428992 24017672 5895790 95072028 59693682 9787351 83060041 78476135 45450901 91377551 34897989...
output:
1519
result:
ok single line: '1519'
Test #13:
score: 0
Accepted
time: 26ms
memory: 6280kb
input:
100000 41710243 45232905 53351778 89714560 96982681 22235410 7684634 53259889 77089257 29419886 37158581 78848193 8365009 79113566 94368469 27287581 31700680 67046259 34383982 47180426 63201452 65370343 75561162 19477633 49906318 83594359 55688393 73113192 74004342 64621956 69375815 96003734 9954962...
output:
100498587
result:
ok single line: '100498587'
Test #14:
score: 0
Accepted
time: 29ms
memory: 6284kb
input:
100000 38762925 55344200 54305622 106972051 51821968 169589545 45523018 6620956 197087638 38530656 55385876 67311610 141685870 123973623 188460327 164526011 50636842 169065310 29090518 139600329 38333124 38989545 173675828 126644723 118573223 49977134 116492332 144683845 144707848 25594342 196444119...
output:
200249292
result:
ok single line: '200249292'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
12000 67380247 48058083 50539890 54456948 72464403 61196967 48639497 52265983 52595328 89697446 60643840 75326052 55617445 29787690 85353339 59430128 90908618 84555886 63888008 89299009 42615299 42329616 38695361 87783498 45042756 44134598 34170435 36108582 54166745 77418667 84650709 36821834 776375...
output:
29521865
result:
ok single line: '29521865'
Test #16:
score: 0
Accepted
time: 4ms
memory: 3828kb
input:
13621 198966 105113 94198 185191 117341 202769 76028 53683 235936 60000 231731 135603 141503 225186 110576 159827 243858 192286 110611 128710 225602 135707 53472 107193 226654 159209 59256 54778 200415 79523 195647 201644 93331 118838 130647 161191 54569 163088 179059 147391 142099 109283 179486 231...
output:
52978
result:
ok single line: '52978'
Test #17:
score: 0
Accepted
time: 4ms
memory: 3844kb
input:
14358 531655 548576 245545 200293 856301 593567 390620 221553 77852 920464 867608 342168 777698 848213 508804 768990 394920 465073 72603 892732 754770 625353 321545 841264 672025 139752 444520 799913 591500 108981 680907 278182 221311 798377 754002 350884 130463 840272 874877 350890 128550 809252 18...
output:
934940
result:
ok single line: '934940'
Test #18:
score: 0
Accepted
time: 261ms
memory: 29640kb
input:
987968 304724418 548006579 232917937 408101562 564917991 900790612 17519505 394150090 110213107 644816595 570435333 999439345 161057400 273796944 124294604 658243863 665155148 714446001 173262257 800067682 762996677 44407745 187536896 126489237 202520265 292378876 574717160 908431181 260306656 24408...
output:
422093862
result:
ok single line: '422093862'
Test #19:
score: 0
Accepted
time: 175ms
memory: 22148kb
input:
669294 898223768 164709542 517553838 728893265 239003604 715287709 397064056 350010430 180336660 159439827 312603750 733083085 939376493 164818961 685879194 976272527 19850056 791441084 694686020 22381310 18420160 942839203 434829411 122112896 880480421 841545908 65064162 143721815 494816341 7061067...
output:
46058
result:
ok single line: '46058'
Test #20:
score: 0
Accepted
time: 9ms
memory: 4056kb
input:
33217 769555754 193816779 81349208 313226942 523595511 762442173 410232574 20876120 490719419 450103941 875194424 96206973 103584613 614497513 941376693 327995001 553090375 650922340 172120330 890657570 487999913 980008486 408621453 26602701 921699400 675060017 513721435 63089909 118020147 332803030...
output:
918828398
result:
ok single line: '918828398'
Test #21:
score: 0
Accepted
time: 272ms
memory: 31764kb
input:
1000000 764153861 543139014 283855932 514881170 198473926 258134642 503221944 26297618 153369613 427093772 487331198 548229432 223640456 679663651 155671600 451551227 491710790 699517055 817763604 32587345 26716478 774748813 183045256 930489913 951550653 705164179 74307947 637976740 439239254 772640...
output:
862724185
result:
ok single line: '862724185'
Test #22:
score: 0
Accepted
time: 266ms
memory: 29432kb
input:
1000000 169127340 27808507 986385512 282264068 928232317 634027946 57667257 577249462 584106342 127041853 428881530 18891386 927192145 732477469 882500627 274368884 811626810 446083540 69490690 699709577 951682439 473502282 498153721 443861999 678864078 95411530 754277088 331428525 256868830 2327894...
output:
2730
result:
ok single line: '2730'
Test #23:
score: 0
Accepted
time: 10ms
memory: 4596kb
input:
51183 999878842 999868927 999864586 999879946 999886261 999889827 950343196 999871443 999869137 999867229 999876072 999689802 876380053 976142945 881999840 999906221 999860566 999899935 999865749 999901933 967368604 999883278 999886393 999814202 999877548 999877529 999863300 999903351 999826758 9998...
output:
999907899
result:
ok single line: '999907899'
Test #24:
score: 0
Accepted
time: 11ms
memory: 4672kb
input:
52003 979215628 999907457 909148156 999873252 999870724 334305909 999869925 999869890 999880109 999881497 999901765 999907203 999880576 999888148 993226368 999881790 999876200 999895313 999877517 999860576 999408053 999864826 999876035 999860428 999898764 999882801 999906592 999901616 999904032 9998...
output:
999907899
result:
ok single line: '999907899'
Test #25:
score: 0
Accepted
time: 61ms
memory: 11432kb
input:
268537 999733632 999816190 999772552 999834477 999683948 999706838 999825616 999890059 999700378 999878917 999839065 999835611 999809434 999867179 999888238 999755209 999573343 999903072 999856942 999655828 999655913 995308507 999765143 999869796 999729249 999775682 999660911 999896544 999897371 999...
output:
999913399
result:
ok single line: '999913399'
Test #26:
score: 0
Accepted
time: 112ms
memory: 16384kb
input:
422572 999851616 999618671 999778317 999574474 999622804 999709294 999527365 999575364 999629969 999615728 999906625 999505825 999623865 999869512 999887823 999914616 999639712 999533326 999652268 999513922 999600811 999796623 999538112 999622071 999501159 999664736 999876919 999768916 999732172 999...
output:
999920999
result:
ok single line: '999920999'
Test #27:
score: 0
Accepted
time: 76ms
memory: 12680kb
input:
304329 999762830 999786372 999890867 999910470 999809637 999601989 999714647 999736549 999806902 999685183 999771640 999872363 999774372 999796911 999690788 999642304 999704386 999645552 985864776 999883047 999754270 999808795 999895302 999614241 999726003 999782012 999717102 999904966 999618181 999...
output:
999914799
result:
ok single line: '999914799'
Test #28:
score: 0
Accepted
time: 235ms
memory: 31380kb
input:
905539 999301805 999069523 999140874 999648937 999917050 999486833 999662637 999304687 999899382 999316098 999770370 999879577 999269759 999585520 999766115 999039391 999276926 999096575 999455713 999581866 999755810 999692964 999838606 999811121 999929265 999692968 999175918 999717800 999467491 999...
output:
999936999
result:
ok single line: '999936999'
Test #29:
score: 0
Accepted
time: 219ms
memory: 28600kb
input:
819485 999244307 999408911 999522693 999561926 999718261 999236788 999169001 999924779 999566077 999753080 999616931 999428571 999754881 999835018 999418283 999796374 999906307 999598281 999236028 999451599 999836614 998954494 999462482 999275065 999188072 999336521 999487525 673318364 999417755 999...
output:
999932399
result:
ok single line: '999932399'
Test #30:
score: 0
Accepted
time: 254ms
memory: 33212kb
input:
960890 999437254 999335676 999647756 999146906 998992845 999427843 999846925 999312415 999364872 999583839 999344146 999762915 999834528 999718670 999027812 999735192 999681605 999845178 999245645 999326844 998987992 999053783 999388399 999084936 999766689 999005269 999483601 998502804 999240453 999...
output:
999939699
result:
ok single line: '999939699'