QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#426352#8747. 朔望yanshanjiahongTL 0ms0kbC++142.9kb2024-05-31 08:23:052024-05-31 08:23:05

Judging History

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

  • [2024-05-31 08:23:05]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-05-31 08:23:05]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define repp(i,j,k) for(int i=j;i>=k;i--)
#define ls(x) x*2
#define rs(x) x*2+1
#define lowbit(x) x&(-x)
#define pii pair<int,int>
#define mp make_pair
#define fir first
#define sec second 
#define int long long
using namespace std;
typedef long long ll;
const int N=25,M=(1<<20)+5,mo=1e9+7,inf=1e9+7;
inline void read(int &p){
	int x=0,w=1;
	char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')w=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+ch-'0';
		ch=getchar();
	}
	p=x*w;
}
int quick_power(int base,int x){
	int res=1;
	while(x){
		if(x&1)res*=base,res%=mo;
		base*=base,base%=mo;
		x>>=1;
	}
	return res;
}
int n,t[N],w[N];
struct divi{
	vector<pii>d;
	friend divi operator+(divi x,divi y){
		divi res;
		for(auto i:x.d){
			bool exi=0;
			rep(j,0,(int)y.d.size()-1){
				if(i.fir==y.d[j].fir)y.d[j].sec+=i.sec,exi=1;
				if(exi)break;
			}
			if(!exi)res.d.push_back(i);
		}
		for(auto j:y.d)
		    res.d.push_back(j); 
		sort(res.d.begin(),res.d.end());
		return res;
	}
}num[N],dif[N][N],dv[N][N];
void print(divi x){
	puts("**");
	for(auto i:x.d){
		printf("!%lld %lld\n",i.fir,i.sec);
	}
	puts("**");
}
divi getd(int x){
	divi res;
	rep(i,2,sqrt(x)){
		if(x<i)break;
		int cnt=0;
		while(x%i==0)
		    x/=i,cnt++;
		if(cnt)res.d.push_back(mp(i,cnt));
	}
	if(x!=1)res.d.push_back(mp(x,1));
	return res;
}
divi getgcd(divi x,divi y){
	divi res;
	int nw=0;
	for(auto i:x.d){
		while(nw<(int)y.d.size()&&y.d[nw].fir<i.fir)
		    nw++;
		if(y.d[nw].fir==i.fir)res.d.push_back(mp(i.fir,min(i.sec,y.d[nw].sec)));
	}
	return res;
}
int cnts[M],tot;
int count(divi x){
	int res=1;
	for(auto i:x.d)
	    res=res*quick_power(i.fir,i.sec)%mo;
	return res;
}
int dp[N][M];
signed main(){
	read(n),tot=(1<<n)-1;
	rep(i,1,n) 
	    read(t[i]);
	rep(i,2,n)
	    read(w[i]);
	rep(i,1,n)
	    num[i]=getd(t[i]);
	rep(i,1,n-1){
		rep(j,i+1,n){
			dif[i][j]=getd(t[j]-t[i]);
			rep(k,1,n)
			    if(i!=k&&j!=k)dv[i][j]=dv[i][j]+num[k];
			dv[i][j]=dv[i][j]+dif[i][j];
		}
	}
	rep(st,1,tot){
		if(__builtin_popcount(st)==1)continue;
		int fir=0,sec=0;
		divi res;
		rep(i,1,n){
			if(!((st>>(i-1))&1))continue;
			if(!fir)fir=i;
			else if(!sec)sec=1,res=dv[fir][i];
			else res=getgcd(res,dv[fir][i]);
		}
		cnts[st]=2*count(res)%mo;
	}
	int ans=0,mult=1;
	rep(i,1,n)
	    mult*=t[i],mult%=mo;
	mult=quick_power(mult,mo-2);
	repp(st,tot,1){
		int nnum=__builtin_popcount(st);
		if(nnum==1)continue;
		rep(i,0,n){
			if(i&&(!((st>>(i-1))&1)))continue;
			rep(j,i+1,n){
				if((st>>(j-1))&1)continue;
				int nw=st|(1<<(j-1));
				dp[i][st]+=(dp[j][nw]+cnts[nw])%mo;
				dp[i][st]%=mo;
			}
		}
		cnts[st]=(cnts[st]-dp[0][st]+mo)%mo;
		ans+=w[nnum]*cnts[st]%mo*mult%mo;
		ans%=mo;
	}
	printf("%lld\n",ans);
	return 0;
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:

20
73415948 190825288 205086969 242726140 280691039 291234110 341933576 379938879 399631744 420807939 421811250 486105558 605031352 645495854 714594262 775221445 793534057 818237037 926135349 940293639
108200337 125078426 163639475 261733041 280562529 287327830 310288774 415301468 419144734 46329977...

output:


result: