QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#18106#59. Determinant of A+Bzqingyu_orz30 294ms6784kbC++142.5kb2022-01-16 11:16:432022-05-04 17:05:41

Judging History

你现在查看的是测评时间为 2022-05-04 17:05:41 的历史记录

  • [2024-05-05 11:54:08]
  • hack成功,自动添加数据
  • (/hack/617)
  • [2024-05-05 11:38:15]
  • hack成功,自动添加数据
  • (/hack/616)
  • [2024-03-04 04:42:21]
  • 管理员手动重测本题所有提交记录
  • 测评结果:30
  • 用时:200ms
  • 内存:6924kb
  • [2024-03-04 04:35:40]
  • hack成功,自动添加数据
  • (/hack/552)
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-04 17:05:41]
  • 评测
  • 测评结果:30
  • 用时:294ms
  • 内存:6784kb
  • [2022-01-16 11:16:43]
  • 提交

answer

#include<bits/stdc++.h>
#define mod 998244353
using namespace std;
int n,a[505][505],b[505][505],f[505][505];
int gs,sg;
inline void swap_r(int x,int y){
	for(int i=1;i<=n;++i){
		swap(a[x][i],a[y][i]);
	}
}
inline void swap_c(int x,int y){
	for(int i=1;i<=n;++i){
		swap(a[i][x],a[i][y]);
	}
}
inline void add_r(int x,int y,int z){
	for(int i=1;i<=n;++i){
		a[y][i]=(a[y][i]+1ll*a[x][i]*z)%mod;
	}
}
inline void add_c(int x,int y,int z){
	for(int i=1;i<=n;++i){
		a[i][y]=(a[i][y]+1ll*a[i][x]*z)%mod;
	}
}
int Inver(int x){
	int ans=1,y=mod-2;
	while(y){
		if(y&1)ans=1ll*ans*x%mod;
		y>>=1,x=1ll*x*x%mod;
	}
	return ans;
}
void Add(int x,int y,int z){
	for(int i=1;i<=n;++i){
		a[y][i]=(a[y][i]+1ll*a[x][i]*z)%mod;
		b[y][i]=(b[y][i]+1ll*b[x][i]*z)%mod;
	}
}
void Gauss(){
	for(int i=1;i<=n;++i){
		while(!b[i][i]){
			for(int j=i+1;j<=n;++j)if(b[i][j]){
				sg=-sg;
				for(int k=1;k<=n;++k){
					swap(b[k][i],b[k][j]);
				}
				break;
			}
			if(!b[i][i]){
				++gs;
				if(gs>n)break;
				for(int j=1;j<=n;++j){
					b[i][j]=a[i][j];
					a[i][j]=0;
				}
				for(int j=1;j<i;++j){
					Add(j,i,-b[i][j]);
				}
			}
		}
		if(gs>n)break;
		int ny=Inver(b[i][i]);
		sg=1ll*sg*b[i][i]%mod;
		for(int j=1;j<=n;++j){
			a[i][j]=1ll*a[i][j]*ny%mod;
			b[i][j]=1ll*b[i][j]*ny%mod;
		}
		for(int j=1;j<=n;++j)if(j!=i&&b[j][i]){
			Add(i,j,-b[j][i]);
		}
	}
	for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)
		a[i][j]=-a[i][j];
}
void Hessenburg(){
	for(int i=1;i<n;++i){
		if(!a[i+1][i]){
			int flag=0;
			for(int j=i+2;j<=n;++j)if(a[j][i]){
				flag=1;
				swap_r(i+1,j);
				swap_c(i+1,j);
				break;
			}
			if(!flag)continue;
		}
		int x=Inver(a[i+1][i]);
		for(int j=i+2;j<=n;++j)if(a[j][i]){
			int xz=1ll*x*a[j][i]%mod;
			add_r(i+1,j,-xz);
			add_c(j,i+1,xz);
		}
	}
}
void Det(){
	f[0][0]=1;
	for(int i=1;i<=n;++i){
		for(int j=0;j<i;++j)
			f[i][j]=-1ll*a[i][i]*f[i-1][j]%mod;
		for(int j=1;j<=i;++j)
			f[i][j]=(f[i][j]+f[i-1][j-1])%mod;
		int S=-a[i][i-1];
		for(int j=i-2;j>=0;--j){
			int cs=1ll*S*a[j+1][i]%mod;
			for(int k=0;k<=j;++k)
				f[i][k]=(f[i][k]+1ll*f[j][k]*cs)%mod;
			S=1ll*S*a[j+1][j]%mod;
		}
	}
}
int main(){
	cin>>n;
	for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)
		scanf("%d",&a[i][j]);
	for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)
		scanf("%d",&b[i][j]);
	gs=0,sg=1;
	Gauss();
	Hessenburg();
	Det();
	for(int i=0;i<=n;++i){
		int aa=(1ll*sg*f[n][min(n+1,i+gs)]%mod+mod)%mod;
		printf("%d",aa);
		if(i==n)printf("\n");
		else printf(" ");
	}
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 4084kb

input:

50
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 179093706 0 0 0 0 0 873235003 0 873022990 0 0 0 0 150372208 0 0 0 0 0 0 0 0
540031202 441544333 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 30490606 0 23238599 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

0 644547870 336800813 930782285 643527407 525833891 798980552 8547640 608876136 81356076 348918790 231614101 134016931 892980328 75063613 624440846 175328178 430188419 771856054 69479030 100997710 968967696 328326469 651863417 397468946 376073019 147780593 398348993 559201975 781231167 493841955 626...

result:

wrong answer 2nd numbers differ - expected: '436083536', found: '644547870'

Subtask #2:

score: 30
Accepted

Test #51:

score: 30
Accepted
time: 257ms
memory: 6752kb

input:

500
0 0 0 0 0 482890969 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1077401 0 0 210804413 0 508044994 0 0 0 398405351 0 0 0 0 0 0 0 171917316 0 0 0 0 0 0 0 0 0 0 0 429230725 0 0 0 0 0 45665526 0 0 0 925078893 0 0 396149045 0 0 0 595858405 0 0 0 0 0 57208...

output:

197564738 776338137 450758758 86100992 615937344 559163914 131406243 401619987 648971457 913370895 305548921 393285962 915689006 605421884 878026660 574429045 573319599 364491109 147359659 277065849 558700076 605737085 416281513 704015976 726983797 205432732 98536178 813856939 885823882 179190007 66...

result:

ok 501 numbers

Test #52:

score: 0
Accepted
time: 278ms
memory: 6752kb

input:

500
524607538 0 0 195818222 598065776 740433868 0 0 0 0 0 0 584106646 508647343 0 0 0 385186156 0 0 0 748826373 0 0 0 709897533 880532113 0 0 0 0 0 0 0 0 0 480030784 0 0 33138693 0 0 0 0 207633173 0 147270533 0 0 0 0 0 172244086 0 277695222 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 385815514 0 947687701 2...

output:

824902737 425089841 111211053 92073920 901320657 429074841 361764105 48023490 25552725 331325644 371920415 490762692 97825049 353418227 830075621 213540283 914362905 715071163 806070758 910602330 331161583 233467656 349280733 861811395 290106373 974369041 564660867 275072365 75983469 522667016 70935...

result:

ok 501 numbers

Test #53:

score: 0
Accepted
time: 265ms
memory: 6784kb

input:

500
0 398190947 624334613 582987942 0 921082574 0 17867538 0 882918848 0 0 0 0 0 0 90859360 987403245 0 0 0 0 0 0 0 0 0 0 0 0 0 403400811 206487768 0 18198869 0 0 0 651523038 0 192277158 0 0 880215749 0 48622723 931175582 0 380135628 0 187644792 600194396 306519041 0 0 0 646257188 970944730 0 0 0 0 ...

output:

529709961 782389501 427087181 171575244 807733566 948768941 227470506 729203216 600000785 571222788 426790680 997717883 801879168 465532628 857973057 906830434 952735394 45567541 544721647 962896743 742244545 82712613 959513155 325015907 233661306 823083787 9502003 223215085 232986129 315518020 8220...

result:

ok 501 numbers

Test #54:

score: 0
Accepted
time: 262ms
memory: 6764kb

input:

500
889477026 0 0 645288850 0 0 0 597784849 276670294 0 11781884 0 0 0 0 102328605 122546943 466795725 0 0 0 0 0 977951016 0 0 0 0 0 0 0 0 0 441400243 0 607727318 981252464 766407804 0 0 0 0 0 0 0 12674018 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 237392793 0 844896171 0 0 0 868060819 811717128 ...

output:

288878507 103918577 627843934 606769115 701195355 204316868 196692744 438647132 951275060 766989005 835482214 627619453 577296224 790244323 616919000 110197298 388088246 175117021 852199104 324078444 225511335 640854847 85621368 111580084 763931389 778949588 371252595 131117484 889375904 163824154 8...

result:

ok 501 numbers

Test #55:

score: 0
Accepted
time: 266ms
memory: 6760kb

input:

500
0 0 472907806 0 0 0 0 0 0 0 0 298001434 0 896885439 0 0 0 0 0 0 0 0 0 0 0 8484835 0 0 0 0 0 0 0 0 0 0 0 0 954775009 0 0 0 0 288641397 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 512435253 0 0 0 0 0 0 0 386794324 0 655001487 0 0 468232155 0 0 0 0 0 0 0 0 75466257 0 0 0 0 0 0 74943...

output:

748044473 495654177 770128837 803264522 500024782 363477079 635161545 374689496 309423961 60457280 220603722 725110497 211554274 483787612 417355740 860542674 222191891 579668034 936747129 810487962 924847717 455094044 702324829 104318236 971133785 696909055 744480349 911219026 235872106 543656615 5...

result:

ok 501 numbers

Test #56:

score: 0
Accepted
time: 294ms
memory: 6672kb

input:

500
0 0 316262547 241295061 242829688 550075323 245190856 935894298 504227016 176442273 184386996 0 575589507 830192730 0 557943520 895719881 60265103 747418748 261971973 0 99105521 0 69394805 134350353 205033556 151945738 123374702 411264285 912324098 94051646 306060455 899455875 830911129 63742779...

output:

381911851 916241926 514339398 858059197 875456460 714921300 302795193 409031920 783184712 867455007 766476017 243857202 697599556 921790119 792928980 251505819 994285379 59773659 613948150 272434631 907707976 207774347 94674353 668702663 837211956 421611818 372233312 483621202 904224325 602569053 47...

result:

ok 501 numbers

Test #57:

score: 0
Accepted
time: 268ms
memory: 6716kb

input:

500
0 0 0 0 0 0 0 610990574 461613184 433655130 0 0 388974760 806398739 360535781 0 0 0 753732657 0 0 0 0 300470084 0 799888093 321915786 0 731888269 93322740 0 0 0 0 0 0 718357562 0 0 470844951 0 0 0 0 249536634 0 0 720846833 0 0 0 0 0 375498602 834962478 0 0 747200658 0 0 0 0 0 0 179664325 5290568...

output:

686260393 252245335 487730469 316503441 65416924 414972730 492614441 687219169 31213691 279281581 975310019 317336196 211707471 522955573 667053639 354126512 154392544 651273989 460079160 129443229 861736087 105977196 569334344 960887538 833748346 509178819 299462294 951455142 655102577 313951685 21...

result:

ok 501 numbers

Test #58:

score: 0
Accepted
time: 290ms
memory: 6772kb

input:

500
105334543 923544035 0 0 916350532 0 893135971 0 38147030 0 787201908 432732664 0 721024223 708486999 0 701283493 0 0 0 763668271 0 109489133 715738358 0 218182028 0 486065021 0 0 0 853561005 114023429 0 0 601209488 0 101719806 611085551 10556195 0 0 200722083 810064594 0 428296558 88047945 0 905...

output:

386146069 360751156 993393533 927105682 228457601 648163753 787797973 522013271 115473192 964895477 558385286 95058804 298276053 139741955 517593941 927888946 390532694 926469984 546568354 927488188 867723462 62784459 519368506 183331379 408840670 685223323 395691605 356482931 538780329 800704761 25...

result:

ok 501 numbers

Test #59:

score: 0
Accepted
time: 268ms
memory: 6776kb

input:

500
557789613 330510931 0 0 518024711 0 177752966 206203179 584083921 0 621770000 463398931 325609625 655715403 0 644837061 920744971 211652106 501844095 0 31815431 0 508411090 0 299431284 579451022 0 0 560290181 405509081 925573968 0 687385031 953919102 11971443 653210418 0 460457820 270650741 0 19...

output:

237337972 304001552 19756092 903398432 956462082 763470480 729301817 271753612 613700267 334841355 744710574 845246375 971151604 973253901 927943894 280393511 949928036 38722121 474176453 8825977 60878082 249547234 597102095 651053724 429068288 490083950 904742452 549860299 952659239 940608813 73417...

result:

ok 501 numbers

Test #60:

score: 0
Accepted
time: 270ms
memory: 6704kb

input:

500
197401552 830689262 490108468 0 0 0 0 776237119 0 0 699253214 0 0 0 0 0 0 0 655156087 0 14751376 0 0 0 0 228028861 0 0 0 0 503139922 29233876 0 0 0 291395502 182147419 0 0 0 0 0 924694232 0 0 0 0 0 295585170 0 0 0 0 0 0 0 985603432 0 0 50944168 0 0 0 0 0 799660697 0 0 0 131935150 0 0 0 542518152...

output:

343481215 28530470 415182965 106440692 639253380 869174304 723450686 994252880 231059922 452274668 353261722 628878909 809794578 375900072 590410066 750447055 418962912 956023947 26017162 793161094 816016177 757605421 521424576 503928843 225335613 154352919 240264199 356448940 826417044 553721500 16...

result:

ok 501 numbers

Subtask #3:

score: 0
Skipped

Dependency #1:

0%