QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#68251 | #1771. 交通规划 | Lenstar | 0 | 0ms | 0kb | C++11 | 4.0kb | 2022-12-15 15:32:33 | 2022-12-15 15:32:36 |
Judging History
answer
#include <bits/stdc++.h>
using pii = std::pair<int64_t, int>;
const int N = 5e2 + 10, M = 5e5 + 10;
inline int read() {
int x = 0, f = 0;
char ch = getchar();
while (!isdigit(ch))
f |= ch == '-', ch = getchar();
while (isdigit(ch))
x = x * 10 + ch - '0', ch = getchar();
return f ? -x : x;
}
int a[N][N], b[N][N], id[N][N], Id[M];
int64_t dis[M], c[N][N], f[N][N];
int tot = 1, fir[M], nex[4 * M], got[4 * M], tak[4 * M];
inline void add(int u, int v, int w) {
// printf("%d %d %d\n", u, v, w);
nex[++tot] = fir[u], fir[u] = tot, got[tot] = v, tak[tot] = w;
nex[++tot] = fir[v], fir[v] = tot, got[tot] = u, tak[tot] = w;
}
int main() {
freopen("traffic.in", "r", stdin);
freopen("traffic.out", "w", stdout);
int n = read(), m = read(), q = read(), cnt = 0;
for (int i = 1; i <= n - 1; ++i)
for (int j = 1; j <= m; ++j)
a[i][j] = read();
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m - 1; ++j)
b[i][j] = read();
for (int i = 0; i <= n; ++i)
for (int j = 0; j <= m; ++j)
id[i][j] = ++cnt;
cnt = 0;
for (int i = 1; i <= m; ++i)
add(id[0][i], id[0][i - 1], 0), Id[++cnt] = id[0][i];
for (int i = 1; i <= n; ++i)
add(id[i][m], id[i - 1][m], 0), Id[++cnt] = id[i][m];
for (int i = m; i >= 1; --i)
add(id[n][i], id[n][i - 1], 0), Id[++cnt] = id[n][i - 1];
for (int i = n; i >= 1; --i)
add(id[i][0], id[i - 1][0], 0), Id[++cnt] = id[i - 1][0];
for (int i = 1; i <= n - 1; ++i)
for (int j = 1; j <= m; ++j)
add(id[i][j], id[i][j - 1], a[i][j]);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m - 1; ++j)
add(id[i][j], id[i - 1][j], b[i][j]);
for (int T = 1; T <= q; ++T) {
int k = read(), s = 0;
std::vector<std::pair<int, int>> vec, ran;
for (int i = 1; i <= k; ++i) {
int w = read(), x = read(), c = read();
vec.emplace_back(x, c), s += c;
tak[x << 1] = tak[x << 1 | 1] = w;
}
if (s == 0 || s == k) {
puts("0");
continue;
}
std::sort(vec.begin(), vec.end());
for (int i = 1; i < vec.size(); ++i)
if (vec[i].second != vec[i - 1].second)
ran.emplace_back(vec[i - 1].first, vec[i].first);
if (vec.back().second != vec.front().second)
ran.emplace_back(vec.back().first, vec.front().first);
memset(c, 0x3f, sizeof(c));
for (int i = 0; i < ran.size(); i += 2) {
int l = ran[i].first, r = ran[i].second;
memset(dis, 0x3f, sizeof(dis));
std::priority_queue<pii, std::vector<pii>, std::greater<pii>> que;
for (int j = l; j < r; ++j)
dis[Id[j]] = 0, que.emplace(0, Id[j]);
while (!que.empty()) {
int u = que.top().second;
int64_t w = que.top().first;
que.pop();
if (dis[u] == w)
for (int i = fir[u]; i; i = nex[i])
if (dis[got[i]] > dis[u] + tak[i])
dis[got[i]] = dis[u] + tak[i], que.emplace(dis[got[i]], got[i]);
}
for (int j = 1; j < ran.size(); j += 2)
c[j][i] = c[i][j] = dis[Id[ran[j].first]];
}
for (int i = 0; i < ran.size(); ++i)
f[i][i + 1] = c[i][i + 1];
for (int len = 4; len <= ran.size(); ++len)
for (int i = 0, j = len - 1; j < ran.size(); ++i, ++j) {
f[i][j] = c[i][j] + f[i + 1][j - 1];
for (int t = i + 1; t <= j; t += 2)
f[i][j] = std::min(f[i][j], f[i][t] + f[t + 1][j]);
}
printf("%lld\n", f[0][ran.size() - 1]);
for (int i = 0; i < vec.size(); ++i)
tak[vec[i].first << 1] = tak[vec[i].first << 1 | 1] = 0;
}
return 0;
}
详细
Test #1:
score: 0
Dangerous Syscalls
input:
5 5 6 59 36 0 57 1 1 0 0 0 2 30 30 52 9 0 39 82 11 61 1 0 75 0 40 2 0 0 37 81 18 0 29 1 33 86 2 2 67 48 22 16 98 1 0 92 10 1 95 12 0 96 3 0 91 15 0 98 11 1 96 6 0 99 16 0 94 2 0 99 5 0 95 19 1 93 20 1 95 9 0 99 7 0 94 18 1 98 8 0 19 94 1 0 100 19 1 95 20 0 93 9 0 98 16 1 100 10 1 98 15 1 99 4 1 94 1...
output:
result:
Test #2:
score: 0
Dangerous Syscalls
input:
5 5 5 17028 678493 790877 16274 4341 53383 504487 629344 922030 634468 13192 2596 992150 561737 9167 2191 50115 854392 272504 148247 3826 16761 15532 1174 17939 2393 505972 217167 939238 668146 306243 631745 440326 319998 649845 15540 10494 756726 237185 867714 17 978310 3 1 949903 11 0 994542 9 0 9...
output:
result:
Test #3:
score: 0
Dangerous Syscalls
input:
18 18 25 60 0 74 45 94 78 74 56 0 0 73 39 77 27 0 31 60 0 0 42 25 0 25 0 0 0 43 0 93 0 66 0 0 87 76 89 89 68 11 0 98 17 56 45 51 0 28 77 53 25 64 0 0 0 81 72 23 0 8 0 0 0 50 68 74 83 63 8 78 0 0 99 0 78 0 20 72 16 0 0 7 96 0 89 5 0 15 11 52 30 58 0 91 0 62 0 56 18 0 47 65 23 0 64 40 36 96 28 0 0 0 6...
output:
result:
Test #4:
score: 0
Dangerous Syscalls
input:
18 18 25 144850 1300 3012 910571 1667 302245 781585 3651 446714 528157 487071 806563 576865 392086 492130 585493 655092 408 433626 3593 809414 4669 196152 613152 811706 871510 842849 941958 647265 4094 875586 89 1826 2540 383507 2331 1157 380 569882 299505 369724 171844 725025 262487 926360 748209 8...
output:
result:
Test #5:
score: 0
Dangerous Syscalls
input:
18 18 25 921710 303100 545306 546775 955183 876761 5227 5144 4339 923175 409 931 719250 706066 596374 941795 652871 1626 3760 684135 4762 4851 333625 914889 707207 25203 288348 391995 4243 40869 992661 196831 521 4110 538441 4053 1459 320224 5375 3834 5200 908526 310 204864 1428 1441 498 691005 2169...
output:
result:
Test #6:
score: 0
Dangerous Syscalls
input:
18 18 6 41 0 70 54 0 0 0 0 48 16 0 85 0 0 14 27 65 0 0 71 0 92 0 60 0 82 36 21 0 95 62 31 45 86 0 52 40 82 46 0 0 19 0 13 0 75 0 67 0 3 80 93 0 0 65 43 57 68 86 90 0 60 40 66 97 53 0 28 94 52 0 34 53 0 0 0 0 0 95 4 0 73 0 0 79 65 0 0 0 62 93 70 89 39 0 77 60 35 0 81 47 0 0 89 27 0 0 82 7 0 57 79 64 ...
output:
result:
Test #7:
score: 0
Dangerous Syscalls
input:
18 18 2 559370 245130 793767 103500 200367 782386 657089 2111 165 455 1869 246801 846898 471034 366710 171420 741520 4536 626613 622992 160877 688283 196734 2991 45 492927 2921 208270 5439 4069 340102 642455 747648 861157 4782 254603 931984 3939 500 962831 122791 770356 236509 4624 813124 52773 5430...
output:
result:
Test #8:
score: 0
Dangerous Syscalls
input:
18 18 6 757988 746842 168959 225708 832393 577307 2360 917573 570138 4076 788016 15458 900498 4191 259935 83 391704 485474 4980 1924 72481 224531 791900 2686 1063 304495 4756 244112 700678 1838 989669 297491 3445 1065 2691 5099 42819 131454 52282 1503 2070 550443 3797 209 5359 4958 2554 986947 15100...
output:
result:
Test #9:
score: 0
Dangerous Syscalls
input:
94 98 25 947 1 922341 557436 403180 297 617267 311987 789 238 909879 505805 353 833 864172 797438 480 855 574460 686419 361234 949019 672023 348854 656346 909031 285918 503354 923357 66859 610 767780 216731 919856 415342 811397 400453 475604 625149 153 290252 187 965423 917294 636 811 963 927397 537...
output:
result:
Test #10:
score: 0
Dangerous Syscalls
input:
92 96 25 976586 342 713477 804 78 77813 62 147 849 866509 681414 940610 645555 231874 545433 429685 41058 693005 736528 529 525390 955709 16455 292611 494716 835385 297 79 165568 148 295144 198 468 392 204342 677670 277 987 346 117148 510291 432025 843839 499508 223 200 730535 627 93635 660383 29758...
output:
result:
Test #11:
score: 0
Dangerous Syscalls
input:
92 93 2 340732 867 555952 299054 794180 683829 905 342 842388 701 336157 171527 76763 623 912355 677982 592293 680 276 190865 527971 132204 691810 174 866427 426511 600623 266 193985 119 771954 547 622170 865 1058 221233 1020 415 684615 605041 650312 451744 859293 459156 884 293 197749 885802 239602...
output:
result:
Test #12:
score: 0
Dangerous Syscalls
input:
98 93 4 815221 703319 635 653 764602 889 677928 787336 741 535174 889637 348496 155455 474060 8 327078 194437 175 128 736358 618401 478844 457906 922 549 319012 710544 295284 653 445425 114275 554 554025 4310 977065 918 411699 437 651 478898 920 878 899 58112 40976 82882 194 404267 191847 523826 216...
output:
result:
Test #13:
score: 0
Dangerous Syscalls
input:
482 492 25 887251 169 184 947382 624873 913082 654552 170 125 87 653496 53 748554 42263 491283 447430 32 203 396273 112595 360091 203 230433 334932 82 436694 988167 407444 21 184 77 666550 260629 843235 153740 814597 758916 119203 327016 388655 117079 154773 15730 160065 476987 792685 102 779747 97 ...
output:
result:
Test #14:
score: 0
Dangerous Syscalls
input:
462 500 25 86666 1 4 249400 31 212502 82912 466680 118 580862 973774 152 568671 786220 471870 941318 83002 821516 509730 83 455746 57 714772 695795 30026 242570 825395 32 41 529723 875944 168 46867 32 26 109016 864100 93 625714 538481 314866 503817 827343 157876 20 613848 385424 134 181 184 461474 6...
output:
result:
Test #15:
score: 0
Dangerous Syscalls
input:
488 464 25 196549 26953 122155 960545 872055 95 94 712413 582438 6 361600 33 72 128601 499596 391138 688044 36 27 557220 847204 78118 325958 111677 412271 14 80330 23 18 539666 956533 130 147 603363 756391 551766 921236 75320 415557 916051 96 805556 112 169669 151 596923 823503 200688 704946 33 168 ...
output:
result:
Test #16:
score: 0
Dangerous Syscalls
input:
499 493 25 834263 232737 613669 34 102 103 18106 761624 600645 98855 15 349849 135 626890 210937 190871 214156 252304 118 305414 707391 731573 103435 75077 191 192 241130 691322 117 440347 794218 305689 386840 822360 87 155 88410 456526 114 272718 193 623731 654616 169 791697 94 366812 599684 509579...
output:
result:
Test #17:
score: 0
Dangerous Syscalls
input:
452 460 4 370508 631303 220 22637 164 475193 100 24 16 280393 471034 65 24 686426 931761 647322 679876 788294 126449 739681 154 995559 69200 483012 113 264414 679982 62 865415 614082 280682 413712 290735 627822 212555 9 511311 711492 262442 34 223215 838704 513886 97 983434 585406 204276 535229 133 ...
output:
result:
Test #18:
score: 0
Dangerous Syscalls
input:
490 471 3 841771 654873 97 982033 174 121 622826 379631 875048 106677 89 380676 915069 527405 165 315591 572473 246513 481641 485618 292094 28 166087 268305 950386 475984 32268 49 906769 765552 641558 81 400401 575629 58605 914686 860962 120 175 187 191500 791124 62 158519 105673 21853 111 171 29506...
output:
result:
Test #19:
score: 0
Dangerous Syscalls
input:
499 465 4 113333 162461 218613 616870 78 385992 934355 50 815645 88 195 4 903300 9091 608535 260967 170393 105 48 148 154 436225 125 344559 627980 22 984383 195 95 556580 722058 176 494053 577266 71 137 770219 386703 197785 821466 445514 246204 533641 171821 160 6 132209 764063 10 516781 647789 102 ...
output:
result:
Test #20:
score: 0
Dangerous Syscalls
input:
500 500 5 25 141 308457 199 176889 417093 149 371163 143 112 253398 630884 125523 79 134 769244 86 72 478879 373383 518327 697805 358192 109 920238 923910 146588 108 57 82 150 42 8 91 779810 897855 80 667833 580511 196 196 332916 128195 181584 37914 747355 548762 449923 682174 457450 184297 457772 3...