QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#526852 | #6343. Bitaro's travel | Qwerty1232# | 15 | 12ms | 3936kb | C++23 | 1.4kb | 2024-08-21 22:44:22 | 2024-08-21 22:44:22 |
Judging History
answer
#include <bits/stdc++.h>
int32_t main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<int> input(n);
for (auto& i : input) {
std::cin >> i;
}
int q;
std::cin >> q;
for (int i = 0; i < q; i++) {
int x;
std::cin >> x;
int64_t ans = 0;
{
int it = std::lower_bound(input.begin(), input.end(), x) - input.begin();
std::pair<int, int> min(1.1e9, -1);
if (it != n) {
min = std::min(min, {abs(input[it] - x), it});
}
if (it > 0) {
min = std::min(min, {abs(input[it - 1] - x), it - 1});
}
ans += min.first;
x = min.second;
}
int it1 = x - 1;
int it2 = x + 1;
while (it1 != -1 && it2 != n) {
auto min = std::min<std::pair<int, int>>({input[x] - input[it1], it1}, {input[it2] - input[x], it2});
ans += min.first;
if (min.second == it1) {
x = it1--;
} else {
x = it2++;
}
}
if (it1 != -1) {
ans += abs(input[0] - input[x]);
}
if (it2 != n) {
ans += abs(input[n - 1] - input[x]);
}
std::cout << ans << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 1ms
memory: 3624kb
input:
2000 154914587 154914588 154914591 154914592 154914594 154914596 154914598 154914599 154914601 154914603 154914608 154914610 154914612 154914615 154914618 154914619 154914621 154914622 154914626 154914627 154914631 154914633 154914636 154914638 154914640 154914641 154914642 154914644 154914645 15491...
output:
809906250
result:
ok 1 number(s): "809906250"
Test #2:
score: 5
Accepted
time: 1ms
memory: 3564kb
input:
2000 356563033 356563037 356563039 356563041 356563043 356563045 356563048 356563050 356563051 356563052 356563054 356563055 356563057 356563060 356563061 356563062 356563065 356563067 356563069 356563074 356563076 356563077 356563079 356563080 356563082 356563085 356563086 356563090 356563091 35656...
output:
722242888
result:
ok 1 number(s): "722242888"
Test #3:
score: 5
Accepted
time: 1ms
memory: 3492kb
input:
2000 24477976 24477978 24477981 24477982 24477986 24477988 24477990 24477992 24477993 24477996 24477998 24477999 24478001 24478002 24478003 24478005 24478007 24478008 24478009 24478011 24478012 24478013 24478015 24478016 24478017 24478019 24478020 24478022 24478024 24478026 24478029 24478031 2447803...
output:
795269579
result:
ok 1 number(s): "795269579"
Test #4:
score: 5
Accepted
time: 1ms
memory: 3540kb
input:
2000 118383953 118383958 118383960 118383964 118383966 118383970 118383971 118383972 118383974 118383976 118383977 118383978 118383979 118383981 118383982 118383983 118383986 118383987 118383989 118383990 118383991 118383993 118383994 118383996 118383998 118383999 118384000 118384002 118384006 11838...
output:
633902161
result:
ok 1 number(s): "633902161"
Test #5:
score: 5
Accepted
time: 1ms
memory: 3608kb
input:
2000 272693597 272693671 272693681 272693702 272693821 272693831 272693847 272693875 272693993 272694064 272694229 272694559 272694705 272694761 272694801 272694938 272695137 272695221 272695495 272695544 497465806 497465807 497465809 497465811 497465813 497465815 497465816 497465817 497465819 49746...
output:
224780330
result:
ok 1 number(s): "224780330"
Test #6:
score: 5
Accepted
time: 1ms
memory: 3612kb
input:
2000 164199708 164199714 164199741 164199803 164199830 164199964 164200182 164200363 164200417 164200604 164200739 164200758 164200777 164201008 164201058 164201062 164201119 164201206 164201308 164201582 568938433 568938436 568938440 568938442 568938446 568938448 568938449 568938452 568938454 56893...
output:
404746823
result:
ok 1 number(s): "404746823"
Test #7:
score: 5
Accepted
time: 0ms
memory: 3748kb
input:
1 964813969 1 24961702
output:
939852267
result:
ok 1 number(s): "939852267"
Test #8:
score: 5
Accepted
time: 0ms
memory: 3544kb
input:
1 492812692 1 492812692
output:
0
result:
ok 1 number(s): "0"
Test #9:
score: 5
Accepted
time: 0ms
memory: 3476kb
input:
1 819738491 1 871545564
output:
51807073
result:
ok 1 number(s): "51807073"
Test #10:
score: 5
Accepted
time: 0ms
memory: 3532kb
input:
1 964813971 1 925278587
output:
39535384
result:
ok 1 number(s): "39535384"
Test #11:
score: 5
Accepted
time: 0ms
memory: 3528kb
input:
2 253257833 492812697 1 801030938
output:
547773105
result:
ok 1 number(s): "547773105"
Test #12:
score: 5
Accepted
time: 0ms
memory: 3528kb
input:
10 122861190 170244470 313637646 547293542 557767683 701410141 705452393 819738518 859150721 987518805 1 857449755
output:
1602648112
result:
ok 1 number(s): "1602648112"
Test #13:
score: 5
Accepted
time: 0ms
memory: 3756kb
input:
2000 346838 1137625 2006182 2714727 3062547 3877790 4774903 5016683 5100124 5947146 6363889 7142496 8219943 9913673 10499786 10641688 10929569 11277685 11325053 11977547 12601991 12646876 13722054 14836426 15008615 15250796 16045457 17235758 17556322 17685977 18102009 19184164 19263658 19974844 2038...
output:
1654008616
result:
ok 1 number(s): "1654008616"
Test #14:
score: 5
Accepted
time: 0ms
memory: 3560kb
input:
2000 743982 1493878 1718132 1810575 1882146 2552776 2611689 3114975 3229588 3341359 3699120 3840597 3904572 5058917 6038144 6194653 6618139 6786522 8387028 8443750 9643914 9829181 10446710 10816676 11402658 12787879 13130024 13352051 13946478 14160206 14209716 14474473 14716259 14983734 15687019 165...
output:
1421041440
result:
ok 1 number(s): "1421041440"
Test #15:
score: 5
Accepted
time: 0ms
memory: 3536kb
input:
2000 303288 1146965 1808284 2456179 2479090 2692039 2724480 3624997 3642488 4829238 4981072 5161924 7384691 8030369 9147077 10341325 10424498 10772436 11533204 12219489 12219994 12527510 13411498 13805137 14640093 14743330 15382882 16704507 16934318 17667539 17748510 18253649 19219338 20280530 20297...
output:
1982070571
result:
ok 1 number(s): "1982070571"
Subtask #2:
score: 10
Accepted
Dependency #1:
100%
Accepted
Test #16:
score: 10
Accepted
time: 8ms
memory: 3864kb
input:
200000 3362993 3362996 3362997 3363002 3363005 3363008 3363009 3363011 3363013 3363015 3363017 3363019 3363022 3363024 3363026 3363030 3363032 3363033 3363035 3363036 3363038 3363040 3363043 3363044 3363045 3363047 3363048 3363049 3363050 3363052 3363053 3363054 3363056 3363057 3363060 3363061 33630...
output:
1253123755
result:
ok 1 number(s): "1253123755"
Test #17:
score: 10
Accepted
time: 12ms
memory: 3820kb
input:
200000 49463 49465 49466 49469 49470 49471 49473 49474 49475 49476 49479 49482 49484 49485 49486 49488 49490 49492 49495 49503 49506 49509 49511 49512 49515 49517 49519 49521 49522 49523 49528 49530 49531 49534 49535 49536 49537 49538 49539 49544 49547 49548 49550 49551 49554 49555 49558 49559 49562...
output:
1688511141
result:
ok 1 number(s): "1688511141"
Test #18:
score: 10
Accepted
time: 12ms
memory: 3828kb
input:
200000 2519385 2519387 2519389 2519391 2519392 2519393 2519395 2519397 2519399 2519400 2519401 2519402 2519407 2519408 2519409 2519414 2519417 2519421 2519422 2519425 2519426 2519427 2519429 2519430 2519433 2519435 2519437 2519440 2519441 2519443 2519444 2519445 2519447 2519448 2519450 2519455 25194...
output:
1501931987
result:
ok 1 number(s): "1501931987"
Test #19:
score: 10
Accepted
time: 12ms
memory: 3904kb
input:
200000 7436901 7436905 7436907 7436908 7436909 7436913 7436916 7436917 7436920 7436921 7436922 7436923 7436925 7436927 7436931 7436933 7436936 7436938 7436941 7436944 7436947 7436948 7436950 7436952 7436954 7436956 7436957 7436959 7436961 7436963 7436965 7436966 7436969 7436971 7436973 7436974 74369...
output:
1771935938
result:
ok 1 number(s): "1771935938"
Test #20:
score: 10
Accepted
time: 7ms
memory: 3936kb
input:
200000 45000691 45000693 45000695 45000696 45000698 45000700 45000701 45000703 45000705 45000708 45000710 45000711 45000712 45000716 45000717 45000718 45000720 45000721 45000722 45000723 45000725 45000727 45000728 45000729 45000731 45000733 45000735 45000736 45000737 45000739 45000741 45000743 45000...
output:
1064147063
result:
ok 1 number(s): "1064147063"
Test #21:
score: 10
Accepted
time: 12ms
memory: 3828kb
input:
200000 5250516 5250518 5250520 5250522 5250524 5250525 5250527 5250529 5250530 5250533 5250535 5250536 5250538 5250540 5250541 5250543 5250545 5250547 5250549 5250550 5250551 5250553 5250555 5250556 5250558 5250560 5250561 5250564 5250567 5250568 5250570 5250573 5250574 5250578 5250581 5250582 52505...
output:
1802633713
result:
ok 1 number(s): "1802633713"
Test #22:
score: 10
Accepted
time: 12ms
memory: 3836kb
input:
200000 61827212 61827216 61827221 61827222 61827223 61827225 61827226 61827228 61827231 61827232 61827235 61827236 61827238 61827240 61827241 61827243 61827244 61827246 61827248 61827250 61827253 61827254 61827256 61827257 61827260 61827261 61827263 61827265 61827266 61827268 61827272 61827273 61827...
output:
1231202945
result:
ok 1 number(s): "1231202945"
Test #23:
score: 10
Accepted
time: 12ms
memory: 3816kb
input:
200000 6461 16888 21388 22690 26075 28748 37518 43692 54726 63506 68089 68214 74411 76830 77202 77258 78577 78980 81554 82694 85919 86290 87790 95906 99082 128500 129722 130180 133703 134802 162914 166030 166333 173867 178199 180455 180824 191455 196406 198191 198195 201127 208417 211429 212076 2127...
output:
1134619264
result:
ok 1 number(s): "1134619264"
Test #24:
score: 10
Accepted
time: 12ms
memory: 3832kb
input:
200000 6073 17506 26350 26659 27386 27891 29276 32363 32396 33218 35965 38925 41070 45188 46001 49478 55459 56076 61468 61901 63436 65020 69571 69610 72566 89021 90100 95567 100955 101172 104374 113982 116752 119237 121670 123692 126841 127028 129299 141274 144123 144537 146491 147818 149993 151385 ...
output:
1627978238
result:
ok 1 number(s): "1627978238"
Test #25:
score: 10
Accepted
time: 9ms
memory: 3856kb
input:
200000 1171 8640 29342 30040 31919 37016 39089 47080 47657 48123 55898 56221 56630 64288 67165 69389 73318 77445 78536 78736 79476 80766 87340 88547 90375 91725 94350 100361 103655 109091 113475 131608 133798 143346 157085 157944 161804 180736 180739 185261 189093 194336 205064 205947 208142 209193 ...
output:
1567112510
result:
ok 1 number(s): "1567112510"
Test #26:
score: 10
Accepted
time: 8ms
memory: 3932kb
input:
200000 198 11195 13692 31357 31516 32440 36297 43191 43298 47998 54392 59762 87583 89610 89934 90101 96327 98356 98634 98985 101712 105244 110557 117162 124917 132969 135196 141775 143285 151905 161407 168205 168559 169770 172030 172771 173167 179504 183511 194428 198897 201792 205391 207070 224933 ...
output:
1466018232
result:
ok 1 number(s): "1466018232"
Test #27:
score: 10
Accepted
time: 12ms
memory: 3812kb
input:
200000 393 4968 13055 13360 18315 21172 39005 44122 48418 54690 60392 68336 69427 73082 73123 73572 80328 83757 88893 104839 106818 109726 117559 121645 132682 136461 137786 150162 152637 174063 175425 177640 179369 184476 185659 186554 205885 206271 207387 211714 222765 228223 229195 247977 258920 ...
output:
1442534979
result:
ok 1 number(s): "1442534979"
Test #28:
score: 10
Accepted
time: 12ms
memory: 3792kb
input:
200000 0 4 5 11 13 16 20 21 22 24 28 30 32 35 38 40 41 45 46 54 55 57 58 61 65 66 75 76 78 79 81 87 95 97 100 104 108 114 117 122 125 129 131 133 134 137 138 141 142 143 149 151 153 155 157 159 162 166 170 173 176 183 184 185 186 191 195 200 202 203 205 206 207 210 215 218 220 223 227 233 236 240 24...
output:
1100443362
result:
ok 1 number(s): "1100443362"
Test #29:
score: 10
Accepted
time: 11ms
memory: 3824kb
input:
200000 1 2 5 8 10 11 12 14 15 19 22 23 30 34 36 40 43 45 51 54 55 57 59 63 65 71 77 79 82 84 89 95 103 110 111 113 115 116 119 120 123 124 128 129 139 145 147 150 152 156 158 159 163 164 169 170 172 177 180 182 184 188 194 196 197 198 201 204 218 219 222 223 226 228 230 234 236 238 240 241 243 246 2...
output:
1092131990
result:
ok 1 number(s): "1092131990"
Test #30:
score: 10
Accepted
time: 11ms
memory: 3820kb
input:
200000 5 7 11 14 16 17 20 22 24 28 29 31 32 33 35 40 46 53 58 61 62 63 67 72 75 76 77 79 84 86 89 92 93 99 100 102 105 107 109 111 114 119 122 124 125 126 128 131 132 135 137 143 145 147 150 151 155 160 161 163 168 172 173 175 177 181 182 184 187 190 192 196 197 210 213 214 217 218 222 225 226 229 2...
output:
1098945476
result:
ok 1 number(s): "1098945476"
Subtask #3:
score: 0
Time Limit Exceeded
Test #31:
score: 0
Time Limit Exceeded
input:
200000 9 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181...
output:
200107 999999991 202154 346046 379455 269768 313076 381369 366120 265794 363817 348433 342292 260613 302587 332141 311760 281789 345769 366459 218270 221124 225466 313243 322095 332977 281351 224651 257342 259560 206246 231269 316285 371811 394056 382486 202443 357928 359464 357158 354417 368006 326...
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%