QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#849041#9903. 最短路径infCraft0 287ms19732kbC++171.5kb2025-01-09 11:26:502025-01-09 11:26:51

Judging History

你现在查看的是最新测评结果

  • [2025-01-09 11:26:51]
  • 评测
  • 测评结果:0
  • 用时:287ms
  • 内存:19732kb
  • [2025-01-09 11:26:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define Yes cout << "Yes\n"
#define No cout << "No\n"
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define fori(x,y) for(int i=(x);i<=(int)(y);++i)
#define forj(x,y) for(int j=(x);j<=(int)(y);++j)
#define fork(x,y) for(int k=(x);k<=(int)(y);++k)

#define debug(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll MOD = 998244353;
ll qpow(ll a,ll p) {ll res=1; while(p) {if (p&1) {res=res*a%MOD;} a=a*a%MOD; p>>=1;} return res;}

int n, q;
const int N = 305;
const int M = 5e5+7;
vector<array<int,3>> query[N];
ll ans[M];

ll g[N][N];
void solve(int l, int r) {
	if (l == r) {
		for (auto [s, t, i]: query[l]) ans[i] = g[s][t];
		return;
	}
	int g2[N][N];
	fori(1, n) forj(1, n) g2[i][j] = g[i][j];
	int mid = l+r>>1;

	fork(l, mid) fori(1, n) forj(1, n) g[i][j] = min(g[i][j], g[i][k]+g[k][j]);
	solve(mid+1, r);
	fori(1, n) forj(1, n) g[i][j] = g2[i][j];

	fork(mid+1, r) fori(1, n) forj(1, n) g[i][j] = min(g[i][j], g[i][k]+g[k][j]);
	solve(l, mid);
	fori(1, n) forj(1, n) g[i][j] = g2[i][j];
}
void solve() {
	cin >> n >> q;
	fori(1, n) forj(1, n) cin >> g[i][j];
	fori(1, q) {
		int s, t, p;
		cin >> s >> t >> p;
		query[p].push_back({s, t, i});
	}
	solve(1, n);
	fori(1, q) cout << ans[i] << endl;
}

signed main() {
	IOS;
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

详细


Pretests


Final Tests

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 8516kb

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:

65676043
-7696351708503393
-5510704155
-4210209691208
-2820318941
-85044848350231014
858398967
-8124074958525724479
-4146013576
-7696350482447607
2989287
377654
-3922547057
-348469546735
1939443861
383758
4163602
478507065
-2136877129
-1417281685
-3050813072031418226
-1192786631
-2378618373
-6433216...

result:

wrong answer 2nd numbers differ - expected: '128648', found: '-7696351708503393'

Test #2:

score: 0
Wrong Answer
time: 8ms
memory: 8440kb

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:

-29360858326
334851
702245276
-3421613237
-1307518722560797524
204465
28215974
-31199269557
-82045992777
-1853261078
1626755934
-1023875688
33496
-1391925627
3023922
-10477253097
977320
1219242435
28243174
-2886451123
-7347355717320585
-129885777187
322009
816431263
1662327667
334809
-3266657826
-32...

result:

wrong answer 1st numbers differ - expected: '270396', found: '-29360858326'

Test #3:

score: 0
Wrong Answer
time: 8ms
memory: 8432kb

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:

-3206779531
-1010601659
368084522
-2498611431
-3940306074
-2121327874
-3102717604
874504
-75957599901
-3790821646652
2077667264
-101191508998
608454
-1204430170
1460725589
-1182703565
-3893491847
-5371389604
770972618
1929592
-3612305926
-1798216887
-132019808329
-5103316188
683644
-4558899344
29600...

result:

wrong answer 1st numbers differ - expected: '2561993', found: '-3206779531'

Test #4:

score: 0
Wrong Answer
time: 202ms
memory: 9724kb

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:

164487
70070
33848
-41973477900600
-63615773803
163213
-8725156570581870922
-3240535818
-12396569063
-1038906217
218252
366116
917130504
45195
49168
66962
122251
-62813899907
210210
-1469443065
-5024721103
2067194
44881
59954
374411098
-1603754202
-1078209765
69521
-1543853468
78293
-782983699
17359...

result:

wrong answer 4th numbers differ - expected: '39326', found: '-41973477900600'

Test #5:

score: 0
Wrong Answer
time: 205ms
memory: 7708kb

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:

-5394472186250
-1549681100
-2025099765
-5846302913
-37810347927
366873
339714
-12362669088
-92759763359
-16848931092
-409306106734227
1167232
-1424746728
106938
-1405283799
-1938926561
-1268534962
-28665901636
186195
3123909
-504162711
-8428163638518958917
1163236836
148594
518134
-3182405453
132238...

result:

wrong answer 1st numbers differ - expected: '172637', found: '-5394472186250'

Test #6:

score: 0
Wrong Answer
time: 284ms
memory: 19732kb

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:

-1027774070
54618
33982
-5161633588385665782
-1722995404
-6974378712
-1520632769
43347
-905306004
58303
-25281190621
76331
-8416893310
-948693379
64935
-846335321
68977
51166
-2523800970
-8854381793208106021
73897
-145367735951809
-1600122853
-141221854244354
-1616447644
78411
-141218419757232
-3479...

result:

wrong answer 1st numbers differ - expected: '994739', found: '-1027774070'

Test #7:

score: 0
Wrong Answer
time: 282ms
memory: 19384kb

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:

-2075108677
27329
78603
-11319574118194
115097
64214
54794
-1018047538
-1709801484
48060
31826
427105
37427
30993
-28305244153
-5396103860980
35095
-1398544300
36501
-13389166209
43375
26171
123760
-16768823724
40607
-3538539811
67048
-3308519470
-53762315804
-307419228
-3963467882
73634
59011
-1008...

result:

wrong answer 1st numbers differ - expected: '52439', found: '-2075108677'

Test #8:

score: 0
Wrong Answer
time: 287ms
memory: 19188kb

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:

54159
293560
56301
-7523548501
-779206872
60385
120895
220425548
-148286862682
63263
-1980060028
-1312058870063
-114641582409358
-1814080464
-485421797
87276
50500
102821
70941
1761130
-754290483
-8604509710201
213854
-84509752
176069
-8604865960625
-5843421857821883857
57550
49112
-620780440004
282...

result:

wrong answer 4th numbers differ - expected: '292181', found: '-7523548501'

Test #9:

score: 0
Wrong Answer
time: 286ms
memory: 19076kb

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:

177525
-63382817226
237199
-4476653696
-1833521456056700938
27318
42093
46619
-3117283752
-2700308643889867691
40589
-1385266813
-5317214612887543273
37048
88229
173568
187342
109950
-3725065004
-2819516791709279482
-1434435512
182615
-8383977379779681296
-2819516792569613288
477729
199693
-19392629...

result:

wrong answer 2nd numbers differ - expected: '35945', found: '-63382817226'

Test #10:

score: 0
Wrong Answer
time: 279ms
memory: 19036kb

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:

113041
140362
-7419235131024261490
-3205299710
83711
-3326768319
-1866323402
3566358
-8496873431
-2887145036
-1047310299
195189
161997
-2286513409
-394565710728257
227657
-5056634032
2635278
-2062496997
138747
-6083685137
414308
129685
59258
-28498616703
-2652463472
-1975727871
-3811118844
121691
-1...

result:

wrong answer 3rd numbers differ - expected: '37931', found: '-7419235131024261490'