QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#462946#8747. 朔望275307894a#TL 2995ms4148kbC++142.5kb2024-07-04 10:12:132024-07-04 10:12:13

Judging History

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

  • [2024-07-04 10:12:13]
  • 评测
  • 测评结果:TL
  • 用时:2995ms
  • 内存:4148kb
  • [2024-07-04 10:12:13]
  • 提交

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=20+5,M=N*4+5,K=1000+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(time(0));
#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;
int n,A[N],B[N];
ll C[N][N],iv[N];
int Ch[N];
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;}
ll ans=0;
void dfs(int x,int y){
	if(!x){
		if(__builtin_popcount(y)<2) return;
		ll mul=1;for(int i=1;i<=Ch[1];i++) mul=mul*C[1][i]%mod;
		mul=mpow(mul);
		mul=mul*(A[__lg(y)+1]-A[__lg(y&-y)+1]+mod)%mod;
		for(int i=__lg(y&-y)+1+1;i<=__lg(y);i++) if(y>>i-1&1) mul=mul*A[i]%mod;
		// gdb(mul);
		mul=mul*mpow(2*(iv[__lg(y&-y)+1]-iv[__lg(y)+1]+mod)%mod)%mod;
		// gdb(mul,y);
		ans+=B[__builtin_popcount(y)]*mpow(mul)%mod;
		return;
	}
	Ch[x]=Ch[x+1];Mc(C[x],C[x+1]);
	dfs(x-1,y);
	if(!y){
		dfs(x-1,y|(1<<x-1));
	}else{
		if(__builtin_popcount(y)^1) C[x][++Ch[x]]=A[x];
		else C[x][++Ch[x]]=A[__lg(y)+1]-A[x];
		static ll D[N];int Dh=0;
		D[Dh=1]=A[__lg(y)+1]-A[x];for(int i=x+1;i<=__lg(y);i++) if(y>>i-1&1) D[++Dh]=A[i];
		for(int i=1;i<=Ch[x];i++){
			ll p=C[x][i];
			for(int j=1;j<=Dh;j++){
				ll w=__gcd(p,D[j]);
				p/=w;D[j]/=w;
			}
			C[x][i]/=p;
		}
		dfs(x-1,y|(1<<x-1));
	}
}
void Solve(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&A[i]),iv[i]=mpow(A[i]);
	for(int i=2;i<=n;i++) scanf("%d",&B[i]);
	for(int i=0;i<=n;i++) for(int j=C[i][0]=1;j<=i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	for(int i=2;i<=n;i++) for(int j=2;j<i;j++) B[i]=(B[i]+(mod-B[j])*C[i][j])%mod;
	dfs(n,0);
	printf("%lld\n",ans%mod);
}
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: 2683ms
memory: 4148kb

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:

153969420

result:

ok single line: '153969420'

Test #2:

score: 0
Accepted
time: 2750ms
memory: 3988kb

input:

20
84235069 157167959 241945024 324983190 344510999 389625308 393693455 492087389 545401834 611823985 699640865 718172624 789215994 804453614 825368584 850396218 864421557 956633895 998178799 998191351
10237096 66048990 113647123 152133403 158116741 170538744 310395982 317219199 388394456 425740854 ...

output:

519880572

result:

ok single line: '519880572'

Test #3:

score: 0
Accepted
time: 2609ms
memory: 3928kb

input:

20
4095671 19344443 19862217 99681209 164768338 179386320 227990671 259927153 291683257 322112421 325703075 386818784 391256396 394175885 530975901 633124435 706843457 768173984 832924754 864889710
181669395 188767026 285808351 330525208 350027130 386025072 475920661 520764065 521827714 550433016 59...

output:

851233434

result:

ok single line: '851233434'

Test #4:

score: 0
Accepted
time: 2807ms
memory: 4024kb

input:

20
18488602 59172425 92169299 108229468 165735372 248082200 359653090 395700282 420721479 428337394 435619427 448440085 536411011 562815310 615404200 639050216 667892289 714428379 894979649 912438198
41226204 51956102 62277661 81215110 107346163 126988480 130550912 189680493 261806109 318225281 3342...

output:

26689156

result:

ok single line: '26689156'

Test #5:

score: 0
Accepted
time: 2324ms
memory: 3960kb

input:

20
17244836 19708384 98541920 123177400 150276428 226646416 241427704 275917376 315334144 320261240 376922844 591251520 620814096 709501824 721819564 810507292 854851156 862241800 918903404 992809844
37518403 39154238 51611231 261298439 269489128 290716487 478588543 499510038 547292150 592769093 605...

output:

696242820

result:

ok single line: '696242820'

Test #6:

score: 0
Accepted
time: 1949ms
memory: 3984kb

input:

20
19247340 57742020 76989360 96236700 211720740 230968080 288710100 365699460 481183500 519678180 558172860 615914880 673656900 731398920 769893600 808388280 866130300 904624980 962367000 981614340
148910987 301586559 480690975 507474360 553446669 561302272 573740192 625086499 671148743 680592047 6...

output:

20117023

result:

ok single line: '20117023'

Test #7:

score: 0
Accepted
time: 2529ms
memory: 4004kb

input:

20
100011990 110013189 113346922 136683053 296702237 313370902 346708232 356709431 403381693 436719023 480057552 486725018 546732212 653411668 853435648 860103114 893440444 913442842 916776575 993452434
1141138 78919305 129681127 130971538 169206258 171357952 287272942 325515992 370177227 409551792 ...

output:

381584175

result:

ok single line: '381584175'

Test #8:

score: 0
Accepted
time: 2338ms
memory: 3988kb

input:

20
27 237 711 8937 26811 78447 222543 235341 310809 667629 706023 932427 2002887 2118069 2797281 8184637 8391843 73661733 220985199 662955597
78118579 107551612 147296745 171423408 186934128 200801750 268972463 317394828 385982506 390033240 391001980 437092765 550017817 591715010 680293234 680931512...

output:

783690675

result:

ok single line: '783690675'

Test #9:

score: 0
Accepted
time: 2358ms
memory: 4004kb

input:

20
42 70 74 105 370 3108 7770 132764 1394022 3485055 4646740 4912268 14736804 34385876 36842010 42982345 73684020 103157628 257894070 515788140
86890917 99349467 100288573 146388649 202635206 211778581 216066880 259441085 272566210 282517395 350709246 351656224 415344730 437321109 439646931 50091437...

output:

209349219

result:

ok single line: '209349219'

Test #10:

score: 0
Accepted
time: 2263ms
memory: 3928kb

input:

20
4 88 94 176 188 376 752 4136 8272 1734416 4769644 9539288 19078576 20379388 56043317 81517552 112086634 224173268 448346536 896693072
25894642 35841446 262580761 270189043 307645170 354483823 407560267 429108535 512245878 556443650 612770928 694158506 707942713 711723446 731755916 769038162 80605...

output:

23272490

result:

ok single line: '23272490'

Test #11:

score: 0
Accepted
time: 2795ms
memory: 3872kb

input:

20
65098209 105270708 130196418 157906062 195294627 315812124 319680266 325491045 390589254 421082832 444772544 455687463 578988894 585883881 631624248 653259674 684259602 806150236 894801018 976473135
3578211 6675920 43758254 129343185 166597720 214323863 321518612 397898341 448294997 459184157 524...

output:

407219779

result:

ok single line: '407219779'

Test #12:

score: 0
Accepted
time: 2932ms
memory: 3892kb

input:

20
10596498 35531952 111942666 145540750 151280704 198810810 267029456 270347450 481991424 488371290 517327338 539044374 553522398 618673506 680417856 707170900 770692758 895379824 956784300 966146082
75262456 81291374 157740574 177382772 224187967 224963690 225088760 329204109 345348134 379665154 4...

output:

681304676

result:

ok single line: '681304676'

Test #13:

score: 0
Accepted
time: 2995ms
memory: 3956kb

input:

20
80 632 4167 86663 143738 173326 175520 195073 1109811 2078199 6632482 6824157 6933040 10706720 21145772 26879006 84583088 106911793 211457720 422915440
3315979 21220087 58651584 91791639 115777919 239960507 323869479 332461958 416544648 435829226 455949270 459939949 546368034 625872179 635845488 ...

output:

261148592

result:

ok single line: '261148592'

Test #14:

score: 0
Accepted
time: 2565ms
memory: 4120kb

input:

20
1 2 48176672 144530016 149491593 240883360 385413376 385853771 398644248 448474779 548135841 597966372 626296736 722650080 747457965 770826752 771707542 797288496 819003424 867180096
265700314 298574772 379948160 392144351 579185844 591466916 600048020 634044117 658216544 752445159 871031259 8828...

output:

783843521

result:

ok single line: '783843521'

Test #15:

score: 0
Accepted
time: 2950ms
memory: 3960kb

input:

20
52975255 99539236 158925765 199078472 298617708 370826785 398156944 481607784 529752550 597235416 602009730 696774652 722411676 796313888 842813622 847604080 895853124 900579335 963215568 995392360
31582213 38258250 53989551 54513361 276550379 311979892 407315184 436245150 439986818 461986609 507...

output:

125576547

result:

ok single line: '125576547'

Test #16:

score: -100
Time Limit Exceeded

input:

20
11850300 25460211 56596334 149241960 166636533 172159522 276676732 286633620 318858833 386716931 424025280 465558144 561416940 606797329 612257455 698808600 716837528 758956766 836200260 936917926
115697223 209194613 351537819 388238328 394873710 413102789 499708726 501043270 526994324 550643109 ...

output:


result: