QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#820732 | #9903. 最短路径 | scanner | 0 | 187ms | 231156kb | C++20 | 1.8kb | 2024-12-19 00:13:15 | 2024-12-19 00:13:15 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pli = pair<ll, int>;
const ll inf = 1e18;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int n, q;
cin >> n >> q;
vector<vector<vector<ll>>> f(n + 1, vector<vector<ll>>(n + 1, vector<ll>(n + 1, inf)));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> f[0][i][j];
}
}
vector<vector<tuple<int, int, int>>> Q(n + 1);
for (int i = 1; i <= q; i++) {
int s, t, p;
cin >> s >> t >> p;
Q[p].push_back({s, t, i});
}
vector<ll> ans(q + 1);
vector<vector<int>> tr(n * 4 + 1);
auto add = [&](auto &&self, int u, int l, int r, int ql, int qr, int p) -> void {
if (ql >= l && qr <= r) {
tr[u].push_back(p);
return;
}
int m = (l + r) >> 1;
if (ql <= m) {
self(self, u << 1, l, m, ql, qr, p);
}
if (qr > m) {
self(self, u << 1 | 1, m + 1, r, ql, qr, p);
}
};
for (int i = 1; i <= n; i++) {
if (i > 1) {
add(add, 1, 1, n, 1, i - 1, i);
}
if (i < n) {
add(add, 1, 1, n, i + 1, n, i);
}
}
auto dfs = [&](auto &&self, int u, int l, int r, int d) -> void {
f[d] = f[d - 1];
for (auto &p : tr[u]) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
f[d][i][j] = min(f[d][i][j], f[d][i][p] + f[d][p][j]);
}
}
}
if (l == r) {
for (auto &[s, t, id] : Q[l]) {
ans[id] = f[d][s][t];
}
return;
}
int m = (l + r) >> 1;
self(self, u << 1, l, m, d + 1);
self(self, u << 1 | 1, m + 1, r, d + 1);
};
dfs(dfs, 1, 1, n, 1);
for (int i = 1; i <= q; i++) {
cout << ans[i] << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 11952kb
input:
100 100 0 7772271323914 22125803016911 3221373 4166251171807 748339783252 34065805188167 50811428832368 1367651438428 24197139580618 6663135541534 27879426632102 15365243414328 10780564011323 2018609024 397712557916 28396067120913 356407886112 44232262619414 162855983068 447276 67425790697675 173378...
output:
64453503 11161 37956 1450762 27112 1450852 92946 29200 413056 46503 27188 61655 18919 422848 387812 34556 1531163 25569 781920 23109 46429 26238 20047 92846 38342 31615 1453886 29200 21267 1533564 23029 47400 6856 389951 401995 12314 45785 35074 18315 64458376 60826 31945 1451847 33014 1456836 47665...
result:
wrong answer 1st numbers differ - expected: '65676043', found: '64453503'
Test #2:
score: 0
Wrong Answer
time: 3ms
memory: 11780kb
input:
100 100 0 17578387256913 79089544497 431 594034211131 5170073338267 19361776466479 4427688105 11926603171157 45072603252 11943768005878 50148978000869 106737346550 27519538966959 37137900185801 3989886236022 15439195175968 19533214331980 4915912422439 66000188414990 29166748845681 354388844 66952055...
output:
250730 51028 63525 106301 62185 51805 223736 25231 228663 243028 41136 843341 15283 67416 2110981 240530 841218 843367 250936 15608305 886434 1437981 302343 11349 12202 55846 278809 62822 31985 6738246 29172 48727 279634 33745 277492 105870 862869 15627539 15840342 102647 280737 54320 40344 54956 41...
result:
wrong answer 1st numbers differ - expected: '270396', found: '250730'
Test #3:
score: 0
Wrong Answer
time: 3ms
memory: 11828kb
input:
100 100 0 773801766444 3840925618 1343152952632 64307613436502 8683601469 45434524869106 81117353046 1987337565207 2858076509641 243425132692 1802644161264 25822170325295 6528483907 41283282749 3826491866697 22344866920790 96931641334570 5174664972951 1538931163479 47147864358837 51639382527727 9867...
output:
1654988 820051 532086 1009203 969308 947186 977687 864738 1969435 2543167 397131 1070 477229 517834 57747532 1581595 1600535 2244160 91335232 1924206 1654656 874291 535210 1600535 528943 2657037 538854 555495 8673 99121 533648 234822 1103535 1012455 389588 192065 394397 533220 1728970 5255446 207747...
result:
wrong answer 1st numbers differ - expected: '2561993', found: '1654988'
Test #4:
score: 0
Wrong Answer
time: 96ms
memory: 219828kb
input:
300 1000 0 1395254281321 81149967048674 808789341190 79819267873907 57367221292974 13013648824390 64258407230458 14605579839044 12975220495832 120220182607 39743014887008 3266138366431 119198662688 28545770063374 17260222479825 21107475181134 55682577272703 13633518098188 40028750178497 550275401200...
output:
154155 33956 30533 23326 1394216 13468 127946 30415 16922 63351 201953 106819 16675 44260 37296 35608 120397 69495 44114 49742 74825 119552 26233 54152 30405 547802 34410 42068 137664 46109 73304 34512 72713 113892 154155 35884 314298 16973 94661 152170 22309 49011 44157 55050 13042 55390 125667 209...
result:
wrong answer 1st numbers differ - expected: '164487', found: '154155'
Test #5:
score: 0
Wrong Answer
time: 96ms
memory: 219868kb
input:
300 1000 0 6409029058 18566975677517 1453118645319 19988064330 32639805173638 1639371569240 698806223545 185977936143 1082787768141 2239906104533 4403543180683 961039210337 4145037246 1858235 2692041139214 2307668378 1339668614 6253996882 17345652389482 1009665462517 17453151773298 3394297603587 135...
output:
119236 109237 45203 15545 94613 352559 321681 161440 102432 74990 77637 68531 76159 102816 48608 52997 71568 82351 123083 61770 49942 154850 149296 124070 93286 68493 83682 88021 1375557 53817 44706 130179 87160 58764 99997 121248 137727 127421 64667 85154 78987 93901 41394 122526 311084 89004 31305...
result:
wrong answer 1st numbers differ - expected: '172637', found: '119236'
Test #6:
score: 0
Wrong Answer
time: 187ms
memory: 231084kb
input:
300 500000 0 87730664049 1603788381608 71952849510530 1142923985 24159738602021 92997246299231 64880292979225 50411033738604 54528465801 31135537246199 231468171471 419 236677264159 38114009155579 2508003778771 57570811058461 24329307886989 292160437 4902439019817 15740104936818 44927292337698 79204...
output:
30381 40560 13122 132299 42337 41340 29131 26208 26240 44884 38573 67991 41387 107003 48557 41326 52946 50236 28474 18608 69079 53436 34130 42833 104480 61272 28430 36536 47281 17693 374923 17435 56552 7097 49525 34631 53743 38580 35191 17635 26343 19560 21803 28366 80959 43732 40496 91053 34395 456...
result:
wrong answer 1st numbers differ - expected: '994739', found: '30381'
Test #7:
score: 0
Wrong Answer
time: 179ms
memory: 231076kb
input:
300 500000 0 52626347413773 1707334632128 70009373655708 25860849031824 32110463708287 3869001849431 346520043666 34919901831451 18512922395 14200680384312 436214584213 79240628473151 14981957306825 1273864589622 475718847939 5308515658147 30868844002 272698735884 23608283030932 509189357147 1289077...
output:
42220 22549 46125 36059 113456 51375 54664 9090 23369 37770 26292 49317 36946 18433 566518 53150 29591 34436 36020 10593 33133 25422 57127 75515 35357 43184 67048 41825 9800 42543 62917 36399 14038 31661 37482 14244 33150 101991 24152 33710 29495 32304 113037 53790 18421 200063 26019 69613 89461 265...
result:
wrong answer 1st numbers differ - expected: '52439', found: '42220'
Test #8:
score: 0
Wrong Answer
time: 167ms
memory: 231156kb
input:
300 500000 0 6330470680301 23874488164149 98626 4160170543478 91396404907 58736315444 12401313360570 14412917281027 38099628392841 282475659499 671873736937 772895099008 19153316198 7022869 27995285198114 11692649915256 7588637657572 823853943323 2206830727999 2151020585 915266887628 5916118204273 1...
output:
33021 237966 45626 27660 47198 28822 71492 242215 98324 56729 32081 2722404 57718 37072 55144 25251 46269 81838 57948 1595433 172623 2742181 180980 42479 130751 232201 763538 47910 40008 58606 201343 34047 16570 178689 13958 2489642 9887 83125 22695 215633 56980 30274 127332 47110 23448 30255 119993...
result:
wrong answer 1st numbers differ - expected: '54159', found: '33021'
Test #9:
score: 0
Wrong Answer
time: 177ms
memory: 230840kb
input:
300 500000 0 54720923847450 10903523785666 4358689132 83283776625462 8218771493732 35488829878660 3339439 6500864120913 61307902687569 53710291769435 19917041512 463251296446 6646718981507 2456241779832 481716427467 7469732375 21084043486 206425878 740838785326 11139961838828 136091417 806439547295 ...
output:
26348 33739 236386 29743 32926 24759 36736 25915 100182 38582 17326 15243 69830 37048 86292 165581 178904 66809 114132 32273 38119 74940 79101 80116 475073 137920 27016 32495 47049 78449 41320 96642 37469 20602 21582 39843 59588 33604 101215 27677 25148 97810 86856 74003 110895 77211 40654 72395 345...
result:
wrong answer 1st numbers differ - expected: '177525', found: '26348'
Test #10:
score: 0
Wrong Answer
time: 169ms
memory: 230844kb
input:
300 500000 0 5722301682716 8452307607009 329027699594 1815251343 30089254283 943061127487 44841695197962 5020142381745 3623788938103 10069313592506 5560807810421 67387215059128 1502958639680 4306022199080 36093310364434 21620815132153 1864471728058 3394408494751 1018569343784 2241919490 118027786703...
output:
26428 19571 27184 410662 80955 127797 594453 3485406 75419 94812 34492 166437 66168 439887 268414 195826 46044 2621485 391269 13589 36121 23156 127537 42562 83967 77834 42899 445581 93276 263097 4659407 78210 78402 511661 67621 24628 61123 28830 104415 461243 84820 3512853 145641 40977 24848 101436 ...
result:
wrong answer 1st numbers differ - expected: '113041', found: '26428'