QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#109814 | #360. Cultivation | bashkort# | 35 | 77ms | 3888kb | C++20 | 3.3kb | 2023-05-30 17:53:39 | 2024-05-31 13:50:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int int64_t
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int R, C, n;
cin >> R >> C >> n;
vector<int> x(n), y(n);
for (int i = 0; i < n; ++i) {
cin >> x[i] >> y[i];
--x[i], --y[i];
}
int ans = R + C;
auto check = [&](int u, int d) -> void {
vector<pair<int, int>> events;
for (int i = 0; i < n; ++i) {
events.emplace_back(max(int(0), x[i] - u), i);
events.emplace_back(min(R, x[i] + d + 1), ~i);
}
events.push_back({0, n});
events.push_back({R - 1, n});
sort(events.begin(), events.end());
int mxl = 0, mxr = 0, mxs = 0;
multiset<int> sy, diff;
sy.insert(-1), sy.insert(C);
diff.insert(C);
auto ins = [&](int i) {
if (i == n) {
return;
}
auto it = sy.lower_bound(y[i]);
int nxt = *it, prv = *prev(it);
diff.extract(nxt - prv - 1);
diff.insert(y[i] - prv - 1);
diff.insert(nxt - y[i] - 1);
sy.insert(y[i]);
};
auto er = [&](int i) {
auto me = sy.find(y[i]);
int nxt = *next(me);
int prv = *prev(me);
sy.erase(me);
diff.extract(nxt - y[i] - 1);
diff.extract(y[i] - prv - 1);
diff.insert(nxt - prv - 1);
};
bool ok = true;
for (int i = 0, j = 0; i < size(events); i = j) {
while (j < size(events) && events[j].first == events[i].first) {
if (events[j].second >= 0) {
ins(events[j].second);
} else {
er(~events[j].second);
}
j += 1;
}
if (events[i].first < R) {
if (size(sy) == 2) {
ok = false;
break;
}
int fi = *next(sy.begin());
int la = *next(sy.rbegin());
mxl = max(mxl, fi);
mxr = max(mxr, C - la - 1);
mxs = max(mxs, *diff.rbegin());
}
}
if (ok) {
ans = min<ll>(ans, max<ll>(mxl + mxr, mxs) + u + d);
}
};
for (int k = 0; k < 2; ++k) {
vector<int> us, ds, sums;
for (int i = 0; i < n; ++i) {
us.push_back(x[i]);
ds.push_back(R - x[i] - 1);
for (int j = 0; j < n; ++j) {
if (x[j] >= x[i]) {
sums.push_back(x[j] - x[i] - 1);
}
}
}
for (int u : us) {
for (int d : ds) {
check(u, d);
}
}
for (int s : sums) {
for (int u : us) {
if (s >= u) {
check(u, s - u);
}
}
for (int d : ds) {
if (s >= d) {
check(s - d, d);
}
}
}
for (int i = 0; i < n; ++i) {
swap(x[i], y[i]);
}
swap(R, C);
}
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: 3648kb
input:
2 4 2 1 1 1 4
output:
3
result:
ok single line: '3'
Test #2:
score: 5
Accepted
time: 0ms
memory: 3876kb
input:
4 1 1 2 1
output:
3
result:
ok single line: '3'
Test #3:
score: 5
Accepted
time: 0ms
memory: 3644kb
input:
3 3 3 1 2 1 3 3 3
output:
3
result:
ok single line: '3'
Test #4:
score: 5
Accepted
time: 1ms
memory: 3612kb
input:
2 2 1 1 2
output:
2
result:
ok single line: '2'
Test #5:
score: 5
Accepted
time: 2ms
memory: 3532kb
input:
4 4 10 4 2 2 3 2 4 4 1 1 2 2 1 4 3 3 3 3 1 1 4
output:
2
result:
ok single line: '2'
Test #6:
score: 5
Accepted
time: 0ms
memory: 3532kb
input:
4 4 1 4 1
output:
6
result:
ok single line: '6'
Test #7:
score: 5
Accepted
time: 0ms
memory: 3652kb
input:
4 4 3 2 2 3 3 1 4
output:
5
result:
ok single line: '5'
Test #8:
score: 5
Accepted
time: 7ms
memory: 3648kb
input:
4 4 15 4 3 2 4 4 4 4 1 3 3 1 2 3 1 2 1 3 4 3 2 4 2 2 3 1 3 2 2 1 4
output:
1
result:
ok single line: '1'
Test #9:
score: 5
Accepted
time: 1ms
memory: 3644kb
input:
4 3 3 2 1 2 3 4 1
output:
3
result:
ok single line: '3'
Test #10:
score: 5
Accepted
time: 0ms
memory: 3588kb
input:
4 4 2 3 4 2 4
output:
5
result:
ok single line: '5'
Test #11:
score: 5
Accepted
time: 0ms
memory: 3876kb
input:
2 4 1 1 2
output:
4
result:
ok single line: '4'
Test #12:
score: 5
Accepted
time: 0ms
memory: 3620kb
input:
3 3 4 2 1 1 1 3 2 3 1
output:
2
result:
ok single line: '2'
Test #13:
score: 5
Accepted
time: 1ms
memory: 3584kb
input:
3 4 3 1 4 3 3 3 4
output:
4
result:
ok single line: '4'
Test #14:
score: 5
Accepted
time: 0ms
memory: 3876kb
input:
3 3 2 2 1 3 3
output:
4
result:
ok single line: '4'
Test #15:
score: 5
Accepted
time: 0ms
memory: 3684kb
input:
4 4 2 2 4 3 1
output:
6
result:
ok single line: '6'
Test #16:
score: 5
Accepted
time: 0ms
memory: 3648kb
input:
4 4 3 2 2 2 1 4 2
output:
4
result:
ok single line: '4'
Subtask #2:
score: 0
Time Limit Exceeded
Dependency #1:
100%
Accepted
Test #17:
score: 10
Accepted
time: 23ms
memory: 3648kb
input:
15 15 20 6 13 14 4 11 13 15 3 12 4 10 4 11 6 8 9 12 12 2 15 4 3 8 15 8 4 3 1 5 10 11 12 8 7 13 10 11 4 1 3
output:
13
result:
ok single line: '13'
Test #18:
score: 0
Time Limit Exceeded
input:
25 25 66 24 6 12 18 11 2 24 18 6 9 20 6 15 19 17 2 15 9 15 20 18 9 5 19 9 2 6 12 22 16 6 2 1 5 14 24 12 21 17 24 10 15 21 1 20 22 11 24 11 4 6 21 18 12 25 20 16 3 18 16 6 4 20 9 6 15 24 14 3 20 9 9 25 9 18 6 4 16 12 7 14 22 20 25 24 10 11 14 17 6 23 23 21 12 18 22 8 23 1 11 17 18 8 5 3 7 1 17 8 12 4...
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 30
Accepted
Test #45:
score: 30
Accepted
time: 14ms
memory: 3812kb
input:
1000000000 1000000000 17 822413671 70423910 260075513 431043546 300945721 793553248 142848049 163787897 392462410 831950868 699005697 111397300 444396260 130450496 642691616 595456084 467968916 463598810 159764248 611476406 929313754 539645102 365153650 964108073 906780716 373514044 970118116 655138...
output:
852626202
result:
ok single line: '852626202'
Test #46:
score: 30
Accepted
time: 59ms
memory: 3592kb
input:
1000000000 1000000000 24 382358372 812500277 617637090 687506454 441176760 562497727 382346048 687504690 205880053 312504652 794110577 62497634 264714161 937490675 970587944 812502893 617647581 62504110 852944701 812498007 88227293 187492617 558814156 687495577 29403236 812494493 911761865 187491781...
output:
904419459
result:
ok single line: '904419459'
Test #47:
score: 30
Accepted
time: 65ms
memory: 3600kb
input:
1000000000 1000000000 25 59999964 299999989 740000035 100000111 139999972 499999797 740000159 899999809 940000104 899999905 459999870 299999853 139999925 899999750 260000183 300000150 260000200 699999915 940000072 99999821 340000223 900000130 739999776 499999813 59999984 700000029 539999767 90000023...
output:
480000793
result:
ok single line: '480000793'
Test #48:
score: 30
Accepted
time: 53ms
memory: 3656kb
input:
1000000000 1000000000 25 496770868 499466029 150245306 140351260 443861207 442170127 915815913 907024280 592352731 580300173 614771420 602707761 545759771 564678204 790963611 795646738 466306333 474998682 700037062 710428701 326403486 341417980 13108429 18468915 296795338 282907012 207909366 2192548...
output:
1967193239
result:
ok single line: '1967193239'
Test #49:
score: 30
Accepted
time: 69ms
memory: 3696kb
input:
1000000000 1000000000 25 508699723 917649746 972134563 24654272 591574312 768222747 342111766 678842208 280650655 335101574 112108587 538128714 232733100 741988808 569340416 313541403 333183415 646381341 348331220 239049882 321253252 46884019 458715217 456559440 11396102 588839952 212356188 55359081...
output:
967430445
result:
ok single line: '967430445'
Test #50:
score: 30
Accepted
time: 70ms
memory: 3888kb
input:
1000000000 1000000000 25 87500002 928571428 712500002 71428571 212500002 71428570 837500001 71428573 912499999 214285715 287500002 785714285 37500003 785714285 962500002 357142856 787500000 785714288 787500003 500000003 462500002 71428570 462500001 357142859 37499999 500000000 462500002 642857144 37...
output:
660714282
result:
ok single line: '660714282'
Test #51:
score: 30
Accepted
time: 42ms
memory: 3664kb
input:
1000000000 1000000000 25 499999999 565789472 499999990 250000002 499999996 749999995 499999999 144736850 499999993 513157893 499999992 644736853 500000010 13157889 499999998 118421056 499999993 197368414 499999990 592105269 499999994 486842107 500000005 276315783 499999994 539473685 499999990 618421...
output:
1131578975
result:
ok single line: '1131578975'
Test #52:
score: 30
Accepted
time: 21ms
memory: 3588kb
input:
999999999 777777777 25 777772259 317438734 467526694 324943812 750092374 316807230 351488629 328182224 670366487 319838016 194662876 330078646 807706262 316391102 682779230 318750710 529347725 323684686 437218310 325726470 284055780 328324426 156380921 332766879 754204172 318252081 631742119 3197068...
output:
1086358403
result:
ok single line: '1086358403'
Test #53:
score: 30
Accepted
time: 44ms
memory: 3584kb
input:
100000000 1000000000 25 75997424 820728673 777782 777777776 777783 777777777 777780 777777778 18626903 845305698 32700264 518597334 66223561 813120928 92237121 497548369 66359837 477082113 51360029 493816356 777776 777777775 777778 777777776 77907935 347786430 777776 777777776 777779 777777786 77777...
output:
434734665
result:
ok single line: '434734665'
Test #54:
score: 30
Accepted
time: 77ms
memory: 3624kb
input:
1000000000 1000000000 25 202384720 191386798 272784910 876112960 134295596 689831109 144607550 725288401 304962179 141608855 184056836 214149818 580684614 928741905 339656490 906353399 222518718 825019927 65386126 415917878 836363213 211099284 885557581 342429798 772605154 167160669 750597218 865168...
output:
1169492481
result:
ok single line: '1169492481'
Test #55:
score: 30
Accepted
time: 66ms
memory: 3628kb
input:
1000000000 1000000000 25 217898725 381443931 363716745 553078122 741451918 906975033 153568070 900704450 12302872 385341608 276235760 349179186 221511192 438759684 177246208 108385423 157609379 88135252 542559523 122476619 676920172 289023879 132864371 527493734 980440215 892433157 465353007 9681278...
output:
936384704
result:
ok single line: '936384704'
Test #56:
score: 30
Accepted
time: 72ms
memory: 3536kb
input:
1000000000 1000000000 25 108777360 996968244 655575871 74556270 426116462 624297074 601010849 48108108 411143918 863537296 176018437 125264437 769284398 653206473 823951690 375380635 675138657 124417631 305117857 433890179 878598110 72028431 322847356 902439915 323815174 873868901 575209775 37455562...
output:
603034352
result:
ok single line: '603034352'
Test #57:
score: 30
Accepted
time: 47ms
memory: 3596kb
input:
335563010 332545567 25 106441293 332545567 117303130 332545567 335563010 272104540 335563010 47336793 335563010 171741328 315104367 332545567 335563010 258033462 174568335 332545567 170964494 332545567 335563010 68594399 304935196 332545567 97310526 332545567 99941575 332545567 12373018 332545567 33...
output:
389908846
result:
ok single line: '389908846'
Test #58:
score: 30
Accepted
time: 77ms
memory: 3592kb
input:
1000000000 1000000000 25 786394982 791216768 119431195 847633609 81087720 1 264330507 432964753 737246186 427050407 922213406 555980523 550982306 581735630 1 1 852080288 1 1 538609505 375220500 773780706 182457491 294843990 1 634980243 421417169 1 253676052 1 601408832 610485554 957268112 249030717 ...
output:
905880429
result:
ok single line: '905880429'
Test #59:
score: 30
Accepted
time: 8ms
memory: 3540kb
input:
1000000000 999999999 25 123456824 987654308 123456819 987654326 123456769 987654289 123456790 987654288 123456802 987654292 123456810 987654352 123456754 987654338 123456799 987654354 123456821 987654331 123456812 987654344 123456754 987654308 123456771 987654347 123456759 987654325 123456794 987654...
output:
1999999906
result:
ok single line: '1999999906'
Test #60:
score: 30
Accepted
time: 73ms
memory: 3520kb
input:
800000000 850000000 25 335835504 189725436 12182937 480593240 63284654 46903085 328812657 436279057 477372871 828400687 194405795 653579540 710586790 72905770 723953376 117573812 64734838 462492145 171374113 120671772 209599317 71273938 194054608 171593430 167629250 52680425 14966053 566230223 12058...
output:
802951025
result:
ok single line: '802951025'
Test #61:
score: 30
Accepted
time: 66ms
memory: 3596kb
input:
1000000000 1000000000 25 62157117 656205518 713439094 288906525 164961619 102056326 876566497 377063232 495641022 967020329 945382229 113881584 172072381 293104404 486897712 389281101 737647745 678839821 248637273 650807852 952485639 634170837 833476502 432041466 148863447 117321892 496035975 546217...
output:
922368183
result:
ok single line: '922368183'
Test #62:
score: 30
Accepted
time: 27ms
memory: 3592kb
input:
1000000000 1000000000 25 499999980 343399132 499999906 225597526 500000007 861547250 499999909 461896002 500000078 691034441 499999919 222514427 499999978 236039953 500000027 612489620 500000050 614406498 500000052 169059154 500000075 102616793 500000005 334144037 500000097 500336043 499999996 14731...
output:
1241069609
result:
ok single line: '1241069609'
Test #63:
score: 30
Accepted
time: 74ms
memory: 3608kb
input:
1000000000 1000000000 25 642065222 981136342 121675139 261963018 735944627 576109400 338153502 307800112 679432262 331837809 40070650 210942580 817625196 535344408 789427854 731652674 774571963 608761006 114198549 290605105 755781608 320483327 257969748 129605173 627155257 309519841 485229109 512450...
output:
939246082
result:
ok single line: '939246082'
Test #64:
score: 30
Accepted
time: 25ms
memory: 3856kb
input:
1000000000 1000000000 25 611076895 363884544 439305553 342413208 438525493 342315624 208146420 313518360 433276048 341659421 891567968 398946036 554628049 356828591 182192780 310274086 713718510 376714855 248891223 318611451 184804702 310600627 197198331 312149761 834859186 391857364 737551904 37969...
output:
1379296760
result:
ok single line: '1379296760'
Subtask #5:
score: 0
Time Limit Exceeded
Dependency #4:
100%
Accepted
Test #65:
score: 0
Time Limit Exceeded
input:
1000000000 1000000000 100 687499990 187500017 691054532 301146309 937499988 312500002 687499994 937500007 579878939 781071766 187500018 562500000 187500009 937500018 562499999 562500008 562499985 687499991 562500019 937500016 62499982 562499999 937500012 812500017 62499989 687500003 812499999 937500...
output:
result:
Subtask #6:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%