QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#831050#9903. 最短路径TaoRan0 1890ms219308kbC++141.6kb2024-12-25 09:50:262024-12-25 09:50:26

Judging History

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

  • [2024-12-25 09:50:26]
  • 评测
  • 测评结果:0
  • 用时:1890ms
  • 内存:219308kb
  • [2024-12-25 09:50:26]
  • 提交

answer

#include<bits/stdc++.h>
#define pt putchar
using namespace std;
typedef long long ll;
const int N=302;
ll read();
void write(ll x);
int n,q;
ll a[N][N];

ll d[N][N][N];
int L[N],R[N];

void add(int id,int x){
	#define ra(i) int i=(R[id]-1)%n+1;i!=L[id]+1;i=i%n+1
	for(ra(i)){
		d[id][x][i]=a[x][i];
		d[id][i][x]=a[i][x];
		for(ra(j)){
			d[id][x][i]=min(d[id][x][i],a[x][j]+d[id][j][i]);
			d[id][i][x]=min(d[id][i][x],a[j][x]+d[id][i][j]);
		}
	}
	for(ra(i)){
		for(ra(j)){
			d[id][i][j]=min(d[id][i][j],d[id][i][x]+d[id][x][j]); 
		} 
	}
	if(L[id]+1==x){
		L[id]++;
	}
	else if(R[id]-1==x){
		R[id]--;
	}
	/*else{
		printf("%d %d %d %d\n",id,L[id],R[id],x);
		assert(0);
	}*/
}

void solve(int l,int r){
	if(l==r){
		return;
	}
	int mid=(l+r)/2;
	memcpy(d[mid+1],d[l],sizeof d[l]);
	L[mid+1]=L[l];R[mid+1]=R[l];
	for(int i=l;i<=mid;i++){
		add(mid+1,i);
	}
	for(int i=r;i>=mid+1;i--){
		add(l,i);
	}
	solve(l,mid);solve(mid+1,r);
}

int main(){
	n=read();q=read();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			a[i][j]=read();
		}
	}
	memset(d[1],63,sizeof d[1]);
	for(int i=1;i<=n;i++){
		d[1][i][i]=0;
	} 
	L[1]=0;R[1]=n+1;
	solve(1,n);
	while(q--){
		int s=read(),t=read();
		write(d[read()][s][t]);pt('\n');
	}
	return 0;
}

ll read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-'){
			f=-1;
		}
		c=getchar();
	}
	while('0'<=c&&c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
void write(ll x){
	if(x<0){
		pt('-');
		x=-x;
	}
	if(x>9){
		write(x/10);
	}
	pt(x%10+'0');
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 0
Wrong Answer
time: 48ms
memory: 75776kb

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:

-6794377390614498793
-9040338789902158866
-9040338792141166993
-9040259957709403691
-6795206930465118872
-6795206922156946311
-9040338797223834339
-9040338818770317066
-9040338806931956635
-9040338791602247729
-6795206885552817189
-6795206887696477355
-9040338792740081196
-9040338784631460035
-90403...

result:

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

Test #2:

score: 0
Wrong Answer
time: 53ms
memory: 77404kb

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:

-9210373853405110359
-6795359942619933432
-6795353440643990364
-9210373836382779705
-6795359941859820107
-6795359927806817347
-8494199910094513790
-9210373845870263824
-7965708469850319607
-9210373814298446549
-6795359717726658076
-6795359914215016261
-6794530198507394940
-9210373813135768404
-67953...

result:

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

Test #3:

score: 0
Wrong Answer
time: 57ms
memory: 79528kb

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:

-8997562793692891750
-8992541827403067472
-7888139688610388077
-7888139426278485472
-8997562814811670744
-8997562801048618819
-8997562791360649548
-7856363707496470067
-8997562821453542105
-8997562826860205119
-8997562796805429551
-8997557888905099577
-7888139659271073031
-8997562797394033232
-89975...

result:

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

Test #4:

score: 0
Wrong Answer
time: 1783ms
memory: 219028kb

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:

-4892252480611847443
-8837617386409136026
-9153246817439908211
-9211443281251685045
-9211443207626889943
-8837617382858506957
-9211443303509995936
-9211443290175026000
-9211443185314810647
-9211443150144877955
-9153246746501925879
-9153246771965706232
-9211443254897048731
-5040049548499881314
-88178...

result:

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

Test #5:

score: 0
Wrong Answer
time: 1768ms
memory: 218824kb

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:

-8752838039025294932
-9150694392009218343
-9150694361584705327
-9150694324480807605
-9150694343402889883
-8875143102090786967
-8875142903778349782
-9150694269613993038
-9150694327963990675
-9150694291077759236
-9150694357601898394
-8857673473998157008
-9150694424829388959
-8875143272600426103
-63657...

result:

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

Test #6:

score: 0
Wrong Answer
time: 1865ms
memory: 219308kb

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:

-8903173445062366093
-8918473953225507161
-8918473957380856926
-8903173486586581964
-8903173561054513655
-8903173485387399959
-8903173440966441247
-8918473892151663483
-8903173492050759667
-8232269934528400436
-8903173406592118254
-8918473823813264472
-8903173491209434231
-8903173473017422437
-89184...

result:

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

Test #7:

score: 0
Wrong Answer
time: 1890ms
memory: 218312kb

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:

-8725559637519959789
-9040656862228860599
-3082042108925265112
-8725559660998778725
-8218779121055835823
-6575021620149449553
-6575020032886322630
-8725559655219986946
-8725559598777837678
-6575023114562428293
-6562181339117549901
-6575017046161249582
-9040656897222516071
-9040657008562067101
-87255...

result:

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

Test #8:

score: 0
Wrong Answer
time: 1874ms
memory: 218216kb

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:

-6364578245603891572
-8759849616536344462
-6370799757787917044
-7827985659327532227
-7827985584016106601
-6345913812648280091
-6370787508842010489
-7827985609330119658
-6849487447890617513
-7963499596743351203
-7827985078004045783
-7827985699380557478
-5870989178008226550
-7827985675203341007
-78279...

result:

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

Test #9:

score: 0
Wrong Answer
time: 1875ms
memory: 218480kb

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:

-6431281380050574638
-9163751718091717327
-6431278241746740796
-9163751750745371588
-9163751738659965446
-6430496205459411298
-6431281375871350609
-6418720186588967448
-9163751717021693992
-9163751834837041316
-6431280663131955664
-9163751689797114724
-9163751689856901892
-8843011976628414579
-64312...

result:

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

Test #10:

score: 0
Wrong Answer
time: 1870ms
memory: 219180kb

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:

-9223325106890722395
-9221629381023970509
-9221325812880947331
-9221325827603102222
-9223324963322676659
-9221325768573346711
-9221325860133958649
-4630031091660191208
-9221325894905000069
-9221325881561685623
-9221325907903290378
-4630031151885521213
-9223325101147369070
-9221325843714555829
-92213...

result:

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