QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#19438 | #1809. Find the MST for Grid | YaoBIG# | WA | 5ms | 3768kb | C++20 | 1.1kb | 2022-01-31 01:52:34 | 2022-05-06 05:22:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int h, w;
cin >> h >> w;
vector<int> as(h, 0), bs(w, 0), cs(h, 0), ds(w, 0);
for (int y = 1; y < h; ++y) cin >> as[y];
for (int x = 0; x < w; ++x) cin >> bs[x];
for (int y = 0; y < h; ++y) cin >> cs[y];
for (int x = 1; x < w; ++x) cin >> ds[x];
ll res = 0;
for (int y = 1; y < h; ++y) res += as[y] + bs[0];
for (int x = 1; x < w; ++x) res += cs[0] + ds[x];
ll sum_bs = 0;
for (int x = 1; x < w; ++x) sum_bs += bs[x];
for (int y = 1; y < h; ++y) res += sum_bs + as[y] * (w-1);
vector<ll> xs(h - 1), ys(w-1);
for (int y = 1; y < h; ++y) xs[y-1] = cs[y] - as[y];
for (int x = 1; x < w; ++x) ys[x-1] = ds[x] - bs[x];
sort(ys.rbegin(), ys.rend());
ys.push_back(0);
for (int x = w-1; x >= 0; --x) ys[x] += ys[x+1];
for (ll x : xs) {
int low = 0;
int high = w - 1;
while(low != high) {
int mid = (low + high) >> 1;
ll y = ys[mid] - ys[mid + 1];
if (x + y <= 0) high = mid;
else low = mid + 1;
}
res += x * (w-1 - high) + ys[high];
}
cout << res << '\n';
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
input:
2 3 1 1 3 6 1 4 1 2
output:
17
result:
ok answer is '17'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3620kb
input:
4 3 1 13 15 3 6 11 3 6 6 11 9 17
output:
173
result:
ok answer is '173'
Test #3:
score: 0
Accepted
time: 3ms
memory: 3688kb
input:
2 3 968418 431416 672770 680574 552160 624114 892963 920468
output:
7379244
result:
ok answer is '7379244'
Test #4:
score: 0
Accepted
time: 3ms
memory: 3636kb
input:
3 2 118689 499942 45109 920606 327638 468788 633079 149844
output:
2587886
result:
ok answer is '2587886'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3552kb
input:
3 3 171815 356177 228641 395286 978617 702666 792511 913883 169671 180825
output:
6127710
result:
ok answer is '6127710'
Test #6:
score: 0
Accepted
time: 3ms
memory: 3692kb
input:
3 4 7184 620183 79780 130738 487556 848611 232818 371375 944380 216990 936022 983989
output:
8438293
result:
ok answer is '8438293'
Test #7:
score: 0
Accepted
time: 2ms
memory: 3648kb
input:
4 3 51985 136713 427919 188504 312899 371141 145631 227550 731171 833357 160747 573726
output:
5493218
result:
ok answer is '5493218'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
7 5 175926 428984 582661 582839 820907 920776 322080 633264 798688 811692 823441 54339 220390 250291 330054 371881 842806 885846 441838 703407 941999 978043
output:
37806417
result:
ok answer is '37806417'
Test #9:
score: 0
Accepted
time: 2ms
memory: 3652kb
input:
9 8 128346 182079 277192 434166 657634 823595 853129 940474 707 292710 363361 404369 494504 600358 796392 872568 95548 456201 544335 582372 695261 827770 860026 928632 994917 160921 262851 319385 402844 959489 982420 982699
output:
69150796
result:
ok answer is '69150796'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3652kb
input:
7 7 390088 456793 662796 811369 863901 997123 174627 272343 294065 376553 692154 797046 972456 76702 401950 405513 470226 553463 682122 826908 106803 293625 306370 544706 575270 828264
output:
44304980
result:
ok answer is '44304980'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
7 7 270291 358878 423424 570235 772251 986431 45308 139839 229024 246723 264432 343181 778141 74325 203070 240656 330399 549696 621374 856760 57300 464802 541216 680595 915767 928652
output:
38909585
result:
ok answer is '38909585'
Test #12:
score: 0
Accepted
time: 3ms
memory: 3636kb
input:
9 8 255312 314659 435326 436128 464484 507292 727368 807464 103501 293849 414270 474996 838635 874511 965537 971583 204709 230699 251434 494013 570649 664454 741866 906547 910970 419608 622510 678766 703125 809137 903338 923781
output:
76479411
result:
ok answer is '76479411'
Test #13:
score: 0
Accepted
time: 2ms
memory: 3552kb
input:
90 15 1569 7812 15560 17225 19225 21440 63872 67763 73422 92647 98398 106522 110109 112693 114487 122224 154052 155699 158235 174012 175798 176730 177959 187239 190924 206750 217783 229076 247986 249130 260497 265264 269052 285315 291931 327499 331976 337424 338165 352012 363333 370568 370943 373038...
output:
1149258768
result:
ok answer is '1149258768'
Test #14:
score: 0
Accepted
time: 3ms
memory: 3664kb
input:
573 762 3338 5419 5645 6157 7116 8262 8393 8399 8717 13114 13179 15879 16350 18675 18777 20835 21329 23456 25635 25875 26218 27153 27503 27953 28438 30788 32050 35179 35273 35416 44186 47640 48200 49720 51545 51756 52851 52886 53427 56462 56541 57087 58701 61500 63233 63449 63650 64330 71582 72299 7...
output:
425651347739
result:
ok answer is '425651347739'
Test #15:
score: -100
Wrong Answer
time: 5ms
memory: 3768kb
input:
5523 5571 187 355 377 524 572 593 624 947 957 973 1147 1287 1861 1911 2165 2436 2560 2806 2875 2924 3028 3035 3090 3210 4339 4372 4520 4531 4580 5137 5395 5686 5710 5802 5994 6494 6816 6919 7012 7349 7609 7783 7833 7943 8016 8242 8327 8422 8475 8489 8608 8619 8659 8686 8709 8738 9353 9423 9651 9692 ...
output:
16259118358976
result:
wrong answer expected '30844827296192', found '16259118358976'