QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#624277#9448. Product Matrix275307894aRE 3ms22716kbC++145.5kb2024-10-09 15:24:442024-10-09 15:24:50

Judging History

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

  • [2024-10-09 15:24:50]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:22716kb
  • [2024-10-09 15:24:44]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=5e5+5,M=(1<<16)+5,K=1000+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;


const int P=1e9+7;
using polyM=vector<ll>;
namespace PolyM{
	const int N=(1<<21)+5;
	using cp=complex<db>;
	int k,tr[N];cp pw[N];
	const db pi=acos(-1);const int Base=(1<<15);
	ll mpow(ll x,int y=P-2){ll ans=1;while(y) y&1&&(ans=ans*x%P),y>>=1,x=x*x%P;return ans;}
	void init(int n){
		for(k=2;k<=n;k<<=1);
		for(int i=0;i<k;i++) tr[i]=(tr[i>>1]>>1)|(i&1?k/2:0);
		for(int i=k/2;i<k;i++) pw[i]=cp(cos(2*pi/k*(i-k/2)),sin(2*pi/k*(i-k/2)));
		for(int i=k/2-1;i;i--) pw[i]=pw[i<<1];
	}
	void fft(cp *A,int k,int flag){
		for(int i=0;i<k;i++) if(i<tr[i]) swap(A[i],A[tr[i]]);
		for(int i=2;i<=k;i<<=1){
			cp *e=pw+i/2;
			for(int j=0;j<k;j+=i){
				for(int h=j;h<j+i/2;h++){
					cp x=A[h+i/2]*e[h-j];
					A[h+i/2]=A[h]-x;A[h]+=x;
				}
			}
		}
		if(flag) return;
		reverse(A+1,A+k);
		for(int i=0;i<k;i++) A[i]/=k;
	}
	ll round(db x){return ll(x+0.5)%P;}
	namespace Public{
		polyM operator *(const polyM &A,const polyM &B){
			static cp a[N],b[N],c[N],d[N];
			init(A.size()+B.size());
			for(int i=0;i<A.size();i++) a[i]=cp(A[i]/Base,A[i]%Base);fill(a+A.size(),a+k,0);
			for(int i=0;i<B.size();i++) b[i]=cp(B[i]/Base,B[i]%Base);fill(b+B.size(),b+k,0);
			fft(a,k,1);fft(b,k,1);
			for(int i=0;i<k;i++){
				cp x=conj(a[(k-i)%k]);
				c[i]=(x+a[i])*cp(0.5,0)*b[i];
				d[i]=(x-a[i])*cp(0,0.5)*b[i];
			}
			fft(c,k,0);fft(d,k,0);
			polyM C(A.size()+B.size()-1);
			for(int i=0;i<C.size();i++) C[i]=((round(c[i].real())*Base+round(c[i].imag()+d[i].real()))*Base+round(d[i].imag()))%P;
			return C;
		}
		polyM& operator *=(polyM &A,const polyM &B){
			return A=A*B;
		}
		polyM operator *(const polyM &A,const int &B){
			polyM C=A;for(auto &i:C) (i*=B)%=P;
			return C;
		}
		polyM& operator *=(polyM &A,const int &B){
			return A=A*B;
		}
		polyM operator +(const polyM &A,const polyM &B){
			polyM C(max(A.size(),B.size()));
			for(int i=0;i<A.size();i++) C[i]=A[i];
			for(int i=0;i<B.size();i++) (C[i]+=B[i])%=P;
			return C;
		}
		polyM& operator +=(polyM &A,const polyM &B){
			return A=A+B;
		}
		polyM operator -(const polyM &A,const polyM &B){
			polyM C(max(A.size(),B.size()));
			for(int i=0;i<A.size();i++) C[i]=A[i];
			for(int i=0;i<B.size();i++) (C[i]+=P-B[i])%=P;
			return C;
		}
		polyM& operator -=(polyM &A,const polyM &B){
			return A=A-B;
		}
		polyM operator %(const polyM &A,const int &B){
			polyM C=A;
			if(C.size()>B) C.resize(B);
			return C;
		}
		polyM& operator %=(polyM &A,const int B){
			return A=A%B;
		}
		polyM inve(polyM A,int n=-1){
			if(n==-1) n=A.size();
			if(n==1) return polyM({(int)mpow(A[0])});
			polyM A0=inve(A%(n+1>>1),n+1>>1);
			return A0*(polyM({2})-A*A0%n)%n;
		}
	}
}using namespace PolyM::Public;

namespace Pow{
	ll p1[N],p2[N];
	const int B=(1<<15);
	void init(int x){
		for(int i=p1[0]=1;i<=B;i++) p1[i]=p1[i-1]*x%mod;
		for(int i=p2[0]=1;i<=B;i++) p2[i]=p2[i-1]*p1[B]%mod;
	}
	ll qry(ll x){
		x=(x%Mod+Mod)%Mod;
		return p1[x&(1<<15)-1]*p2[x>>15]%mod;
	}
}



int n,m;
ll mpow(ll x,int y=mod-2){ll ans=1;while(y) y&1&&(ans=ans*x%mod),y>>=1,x=x*x%mod;return ans;}
using mat=array<array<ll,6>,6>;
mat operator *(const mat &A,const mat &B){
	mat C;for(int i=0;i<n;i++) C[i].fill(0);
	for(int h=0;h<n;h++) for(int i=0;i<n;i++) for(int j=0;j<n;j++) (C[i][j]+=A[i][h]*B[h][j])%=mod;
	return C;
}
mat C[M*2];
mat A,B;
polyM f;
void transdot(){
	for(int i=0;i<2*m;i++) for(int x=0;x<n;x++) for(int y=0;y<n;y++) C[i][x][y]=(A[x][y]*Pow::qry(i)+B[x][y])%mod;
	for(int i=m-1;i;i--) C[i-1]=C[i-1]*C[i];
	mat w;for(int i=0;i<n;i++) w[i].fill(0),w[i][i]=1;
	f.resize(m+1);
	for(int i=0;i<m;i++){
		f[i]=(C[i]*w)[0][0];
		w=w*C[i+m];
	}
	f[m]=w[0][0];
}
polyM g;
polyM CZT(polyM f){
	polyM g(m+1);
	for(int i=0;i<=m;i++) for(int j=0;j<=m;j++) (g[i]+=f[j]*Pow::qry(-1ll*i*j))%=mod;
	return g;
}
void Solve(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) scanf("%lld",&A[i][j]);
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) scanf("%lld",&B[i][j]);
	Pow::init(2);
	transdot();
	ll mul=1;for(int i=1;i<=m;i++) (mul*=mod+1-Pow::qry(i))%=mod;
	mul=mpow(mul);
	for(int i=0;i<=m;i++){
		(f[i]*=mul)%=mod;
		(f[i]*=Pow::qry(-1ll*i*m))%=mod;
		(mul*=mpow(mod+1-Pow::qry(-i-1)))%=mod;
		(mul*=mod+1-Pow::qry(m-i))%=mod;
	}
	g=polyM({1});
	for(int i=0;i<=m;i++) g*=polyM({mod-Pow::qry(i),1});
	gdb(g[0]);
	for(int i=0;i<=m;i++) (f[i]*=mod-Pow::qry(-i))%=mod;
	f=CZT(f)*g;
	for(int i=0;i<=m;i++) printf("%lld\n",f[i]);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 18612kb

input:

2 2
1 2
3 4
2 0
1 2

output:

4
8
14

result:

ok 3 number(s): "4 8 14"

Test #2:

score: 0
Accepted
time: 0ms
memory: 20516kb

input:

4 10
520471651 866160932 848899741 650346545
756377215 402412491 920748640 255249004
371442152 93295238 350011159 679848583
528399020 957465601 22001245 407745834
363922864 418156995 324388560 611306817
671914474 323815171 638034305 796072406
765823638 254662378 175686978 123364350
786531344 3967179...

output:

890467395
623743197
432365684
555543126
145580696
550546744
959254454
836036617
945090197
106843161
866547396

result:

ok 11 numbers

Test #3:

score: 0
Accepted
time: 0ms
memory: 18552kb

input:

6 23
101670804 457970042 521121852 851881468 298366530 271962368
881900040 161849089 409608300 527884448 898980182 538728808
624037110 955334452 644656371 684645088 612630196 365375437
135489465 838789241 374389562 238291227 977400760 496900790
921432977 606711088 740916866 405856539 822796504 19906...

output:

18827363
93291123
549166310
727345493
212460686
835043567
382235992
234331494
126083178
340949995
361327462
549134620
481914498
34075195
89718312
945811332
898724999
944812555
123616792
779724718
995912550
188150326
361531843
801483934

result:

ok 24 numbers

Test #4:

score: 0
Accepted
time: 0ms
memory: 18624kb

input:

1 1
850150743
201109093

output:

201109093
850150743

result:

ok 2 number(s): "201109093 850150743"

Test #5:

score: 0
Accepted
time: 0ms
memory: 22716kb

input:

2 1
838417478 568611358
348881562 259739663
684020320 849564252
7622864 342206654

output:

684020320
838417478

result:

ok 2 number(s): "684020320 838417478"

Test #6:

score: 0
Accepted
time: 3ms
memory: 18608kb

input:

3 1
662626648 989629820 447555531
504352706 537983436 981463385
633227491 799236931 264904138
510263941 30128899 644015027
642994715 674480107 494744466
113567281 686079810 29940910

output:

510263941
662626648

result:

ok 2 number(s): "510263941 662626648"

Test #7:

score: 0
Accepted
time: 0ms
memory: 18492kb

input:

4 1
698286849 108948691 370848972 861145616
308345962 492551526 837788523 735191312
813226172 232618279 121444192 64535733
172831199 302337428 438860400 394173985
968865126 421436111 675658174 967155308
675554219 293733850 793671127 135966551
267239055 24766491 712336945 25719396
621692331 201339445...

output:

968865126
698286849

result:

ok 2 number(s): "968865126 698286849"

Test #8:

score: 0
Accepted
time: 0ms
memory: 18604kb

input:

5 1
346030494 348813388 950014436 351718810 389309705
819298156 278971731 721089919 34315191 136072724
977938439 445268765 725373786 92574089 40828378
81532232 217673244 195836050 397811725 905085770
76139672 852963918 237501084 582369241 723129091
510859036 368205749 459903015 796344358 178557942
9...

output:

510859036
346030494

result:

ok 2 number(s): "510859036 346030494"

Test #9:

score: 0
Accepted
time: 0ms
memory: 18608kb

input:

6 1
269535050 794196606 377757516 516758696 739552010 15300040
523493270 110895534 879184568 693817999 162914386 60443980
122215232 3304271 774066505 279824412 19713957 620002064
784042807 447807660 446909111 377390001 200803795 138848111
379227514 56112455 336718555 609352443 37005361 252594923
861...

output:

552563198
269535050

result:

ok 2 number(s): "552563198 269535050"

Test #10:

score: -100
Runtime Error

input:

1 500000
706182264
736952709

output:


result: