QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#787133#8747. 朔望ffffycTL 0ms0kbC++142.5kb2024-11-27 10:00:262024-11-27 10:00:33

Judging History

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

  • [2024-11-27 10:00:33]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-11-27 10:00:26]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lll __int128
namespace IO{//by cyffff
	int len=0;
	char ibuf[(1<<21)+1],*iS,*iT,out[(1<<25)+1];
	#if ONLINE_JUDGE
	#define gh() (iS==iT?iT=(iS=ibuf)+fread(ibuf,1,(1<<21)+1,stdin),(iS==iT?EOF:*iS++):*iS++)
 	#else
	#define gh() getchar()
	#endif
	#define reg register
	inline int read(){
		reg char ch=gh();
		reg int x=0;
		reg char t=0;
		while(ch<'0'||ch>'9')   t|=ch=='-',ch=gh();
		while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=gh();
		return t?-x:x;
	}
	inline void putc(char ch){
		out[len++]=ch;
	}
	template<class T>
	inline void write(T x){
		if(x<0)putc('-'),x=-x;
		if(x>9)write(x/10);
		out[len++]=x%10+48;
	}
	inline void flush(){
		fwrite(out,1,len,stdout);
		len=0;
	}
	inline char getc(){
		char ch=gh();
		while(ch<'A'||ch>'Z') ch=gh();
		return ch;
	}
}
using IO::read;
using IO::write;
using IO::flush;
using IO::getc;
using IO::putc;
#define pii pair<int,int>
#define mpr make_pair
#define fir first
#define sec second
const int N=20+5,mod=1e9+7;
inline int add(int a,int b){ return a+b>=mod?a+b-mod:a+b; }
inline int dec(int a,int b){ return a>=b?a-b:a+mod-b; }
inline void inc(int &a,int b){ a=a+b>=mod?a+b-mod:a+b; }
inline int qpow(int x,int y){
	int res=1;
	while(y){
		if(y&1) res=1ll*res*x%mod;
		x=1ll*x*x%mod;
		y>>=1;
	}
	return res;
}
int n,t[N],w[N],p[N],f[N],C[N][N];
ll x[N],y[N],b[N],c[N];
int main(){
	n=read();
	for(int i=0;i<n;i++)
		t[i]=read();
	for(int i=2;i<=n;i++)
		w[i]=read();
	for(int i=0;i<=n;i++){
		C[i][0]=1;
		for(int j=1;j<=i;j++)
			C[i][j]=add(C[i-1][j-1],C[i-1][j]);
	}
	int u=1<<n;
	for(int s=0;s<u;s++){
		if(__builtin_popcount(s)<=1) continue;
		int ct=0;
		for(int i=0;i<n;i++)
			if(s>>i&1)
				p[ct++]=i;
		for(int i=0;i<ct;i++)
			x[i]=t[p[i]]-t[p[0]],y[i]=t[p[i]];
		for(int i=1;i<ct;i++){
			int tc=0;
			c[i]=x[i];
			for(int j=1;j<i;j++) c[j]=y[j];
			b[i]=i==1?x[i]:y[i];
			for(int j=1;j<=i;j++){
				int p=1;
				for(int k=1;k<=i&&p!=b[j];k++){
					int w=__gcd(b[j]/p,c[k]);
					c[k]/=w,p*=w;
				}
				b[j]=p;
			}
		}
		ll u=1,v=1;
		for(int i=1;i<ct;i++) u=u*b[i]%mod;
		for(int i=0;i<ct;i++) v=v*y[i]%mod;
//		printf("%d %d/%d\n",s,u,v);
		inc(f[ct],2ll*u*qpow(v,mod-2)%mod);
	}
	int ans=0;
	for(int i=2;i<=n;i++){
		int s=0;
		for(int j=i;j<=n;j++){
			int v=1ll*f[j]*C[j][i]%mod;
			if(j-i&1) v=dec(0,v);
			inc(s,v);
		}
		inc(ans,1ll*s*w[i]%mod);
	}
	write(ans);
	flush();
}

詳細信息

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: