求条,玄关
查看原帖
求条,玄关
908001
YabukiJoe楼主2025/7/27 15:19

WA 60pts

#include<bits/stdc++.h>
#define LL unsigned long long
#define inf 0xffffffffffffffffull
using namespace std;
const int N=105,M=1e4+5;
int n,k;
LL a[M],b[M];
struct matrix{
	LL c[N][N];
	int x,y;
	matrix(){memset(c,0,sizeof c);}
}res,A;
matrix operator*(matrix a,matrix b){
	matrix c;c.x=a.x,c.y=b.y;
	for(int i=1;i<=a.x;i++){
		for(int j=1;j<=b.y;j++){
			for(int k=1;k<=a.y;k++){
				c.c[i][j]|=(a.c[i][k]&b.c[k][j]);
			}
		}
	}
	return c;
}
matrix qpow(matrix a,int b){
    res=a;
    while(b){
    	if(b&1) res=res*a;
    	a=a*a;b>>=1;
	}
	return res;
}
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;i++) scanf("%llu",&a[i]);
	for(int i=1;i<=k;i++) scanf("%llu",&b[i]);
	if(n<=k){printf("%llu\n",a[n]);return 0;}
	reverse(b+1,b+k+1);
	A.x=A.y=k;
	for(int i=1;i<=k;i++) A.c[i][1]=b[i];
	for(int i=2;i<=k;i++) A.c[i-1][i]=inf;
	A=qpow(A,n-k+1);
    res.x=1,res.y=k;
    for(int i=1;i<=k;i++) res.c[1][i]=a[k-i+1];
    res=res*A;
    printf("%llu\n",res.c[1][1]);
	return 0;
}
2025/7/27 15:19
加载中...