QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#840800#9903. 最短路径iris2617#0 983ms57340kbC++232.1kb2025-01-03 03:41:532025-01-03 03:41:53

Judging History

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

  • [2025-01-03 03:41:53]
  • 评测
  • 测评结果:0
  • 用时:983ms
  • 内存:57340kb
  • [2025-01-03 03:41:53]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define matsuri pair<int,int>
//const int iris = 1e9+7;
const int iris = 998244353;
using namespace std;

const int N = 300;

vector<vector<int> > arr(N+1, vector<int>(N+1)), dis(N+1, vector<int>(N+1, 1e18));
vector<vector<int> > st(N*4);
vector<vector<tuple<int,int,int> > > qq(N+1);
vector<int> ok;
vector<int> ans;
int n;

void add(int i,int l,int r,int L,int R,int x)
{
	int m=l+(r-l)/2;
	if(L<=l && r<=R)
		st[i].emplace_back(x);
	else if(R<=m)
		add(i*2,l,m,L,R,x);
	else if(L>m)
		add(i*2+1, m+1, r, L, R, x);
	else
	{
		add(i*2,l,m,L,R,x);
		add(i*2+1, m+1, r, L, R, x);
	}
}

void sana(int i,int l,int r)
{
	vector<tuple<int,int,int> > rev;
	
	auto up=[&](int a,int b,int c)
	{
		if(c<dis[a][b])
		{
			rev.emplace_back(a,b,dis[a][b]);
			dis[a][b]=c;
		}
	};
	
	for(int k:st[i])
	{
		ok.emplace_back(k);
		for(int i:ok)
		{
			up(k,i,arr[k][i]);
			up(i,k,arr[i][k]);
		}
		for(int i:ok)
		{
			for(int j:ok)
			{
				up(i,j,dis[i][k]+dis[k][j]);
				up(i,k,dis[i][j]+dis[j][k]);
				up(k,i,dis[k][j]+dis[j][i]);
			}
		}
	}
	
	if(l==r)
	{
		for(auto [s,t,id]:qq[l])
			ans[id]=dis[s][t];
	}
	else
	{
		int m=l+(r-l)/2;
		sana(i*2,l,m);
		sana(i*2+1,m+1,r);
	}
	
	/*cout<<" owo "<<i<<' '<<l<<' '<<r<<'\n';
	for(int x:ok)
	{
		cout<<' '<<x;
	}
	cout<<'\n';
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cout<<dis[i][j]<<' ';
		}
		cout<<'\n';
	}*/
	
	reverse(rev.begin(), rev.end());
	for(auto &[a,b,c]:rev)
		dis[a][b]=c;
	for(int &x:st[i])
		ok.pop_back();
}

void solve()
{
	int q;
	cin>>n>>q;
	ans.resize(q);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			cin>>arr[i][j];
	for(int i=1;i<=n;i++)
		dis[i][i]=0;
	for(int i=1;i<=n;i++)
	{
		if(i>1)
			add(1,1,n,1,i-1,i);
		if(i<n)
			add(1,1,n,i+1,n,i);
	}
	for(int i=0;i<q;i++)
	{
		int s,t,p;
		cin>>s>>t>>p;
		qq[p].emplace_back(s,t,i);
	}
	sana(1,1,n);
	for(int x:ans)
		cout<<x<<'\n';
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int T=1;
	//cin>>T;
	while(T--)
		solve();

	return 0;
}

詳細信息


Pretests


Final Tests

Test #1:

score: 0
Wrong Answer
time: 30ms
memory: 7088kb

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:

66780767
4580203
2147723
40928242
4718157
3574812
46686875
324593
1589266
350083
15458417
395822788
1291868
3731752
39032539
7237520
5203322
67955471
1914167
7114143
65577458
4270585
69093837
7225976
38683069
129064547
4451143
3905153
46762807
29374024
1449806
371747
28870611
1258112
983703
1218336
...

result:

wrong answer 1st numbers differ - expected: '65676043', found: '66780767'

Test #2:

score: 0
Wrong Answer
time: 28ms
memory: 6980kb

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:

270396
436317954
6596535
30171406
11123137
1274264
32916647
1111588
3698845
52779524
158232
846978
72217521
1129494
270837003
2187617
66175245
3212619
127478114
15626518
2087857
3067886
629338
6201248
47849525
43728797
2398777
1513386
11431526
22619054
66450141
3358165
17051482
36671752
3597905
8877...

result:

wrong answer 2nd numbers differ - expected: '334851', found: '436317954'

Test #3:

score: 0
Wrong Answer
time: 21ms
memory: 6984kb

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:

27009138
24069010
3543217
4784691
3845156
6186618
4171777
6720541
2513906
2550089
1892999
3429807
2378804
7617454
58077849
1616486
131754819
95987343
91338615
2466278
2561661
951355
13469968
13207763
31625960
12167200
13473612
4378460
13929244
143609353
46802011
4091479
1603846
316263250
8425276
211...

result:

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

Test #4:

score: 0
Wrong Answer
time: 863ms
memory: 35732kb

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:

7620911
1066986
113662
39326
2633238
573641
207364
110253
400684
761712
239497
502863
79979
338687
1060482
151048
471917
686175
370927
244431
144055
2067194
496740
449106
283562
736132
186219
726699
155337
1155315
243266
2320897
4617222
1029160
2670137
2130917
343066
1585178
844018
523516
2322002
28...

result:

wrong answer 1st numbers differ - expected: '164487', found: '7620911'

Test #5:

score: 0
Wrong Answer
time: 864ms
memory: 37684kb

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:

250982
125082
534732
244570
504445
9560733
883379
15268375
1539957
1941222
249428
1215778
241246
1406482
414592
524861
1541635
172862
268491
6119292
862138
224190
457228
3080263
709799
532625
2288063
1057742
1973585
420540
1952041
149519
303658
289881
3734873
669435
1095487
376717
140327
2365975
334...

result:

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

Test #6:

score: 0
Wrong Answer
time: 983ms
memory: 57340kb

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:

1301712
689144
1681370
2368171
110510
1691655
154806
2568422
69314
792641
57977
487495
616650
995912
870251
1243400
76735
5496259
332016
589494
1261921
6474509
285021
50299
254038
1282237
4884145
292837
1056328
2075886
473606
62861
71237
2736904
1971392
550516
23857142
71341
190192
2463792
56363
489...

result:

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

Test #7:

score: 0
Wrong Answer
time: 970ms
memory: 56604kb

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:

448032
67376812
2807790
4587627
300015
1591161
439743
166358
1136042
1661045
25322233
1164246
2056284
63360
1191464
283808
8956740
48778
18186954
214657
2381212
541359
470732
109881
243060
1146279
72815
263134
330157
472793
223958
4870336
530655
136265
97516
609457
38702
194061
36831621
1828550
4303...

result:

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

Test #8:

score: 0
Wrong Answer
time: 959ms
memory: 55116kb

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:

283252
515990
379540
292181
635632
347321
1421697
1165335
102254
494430
1692880
2859943
403139
65242
185784
2445929
1314583
4734853
1729220
3787606
1963783
2981113
2081503
80979
203374
336891
1105315
967965
826485
79006
6299888
345363
121931
1075288
58137
3454737
110018
275872
549905
361255
99885
31...

result:

wrong answer 1st numbers differ - expected: '54159', found: '283252'

Test #9:

score: 0
Wrong Answer
time: 963ms
memory: 54916kb

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:

6406614
35945
681632
142307
334796
3859926
247990
2382809
3251497
361232
1165485
62441
985444
129859
231012
1702289
1291695
1188187
211824
426320
2839020
895965
459361
593282
1973521
20930077
71286
54160
1733441
513027
23994561
7216809
73628
27661058
536834
150853
2436198
1497085
601254
117444
84989...

result:

wrong answer 1st numbers differ - expected: '177525', found: '6406614'

Test #10:

score: 0
Wrong Answer
time: 969ms
memory: 53932kb

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:

159705
12887759
1389185
3293542
856568
135839
995600
6738897
124010
187656
178330
2034615
161997
852392
5214193
9835662
123722
3083783
548897
2815852
1485566
21764218
129685
6650661
17016654
81699
53646
455834
5011607
854433
5645954
378627
11949444
1476687
67621
313229
7725802
972460
3182937
1071668...

result:

wrong answer 1st numbers differ - expected: '113041', found: '159705'