QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#591050#7301. Even Three is OddhyfansAC ✓94ms109100kbC++203.1kb2024-09-26 13:48:422024-09-26 13:48:45

Judging History

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

  • [2024-09-26 13:48:45]
  • 评测
  • 测评结果:AC
  • 用时:94ms
  • 内存:109100kb
  • [2024-09-26 13:48:42]
  • 提交

answer

// @Nullptr_qwq @Nullptr_qwQ @Nullptr_qWq @Nullptr_qWQ @Nullptr_Qwq @Nullptr_QwQ @Nullptr_QWq @Nullptr_QWQ
//File uses UTF-8 encoding.
//By: Luogu@tzl_Dedicatus545(UID:308854) Yuanshen@tzl_Dedicatus(UID:273152640)
//Ayaka bless me!
// #define _TZL_DEBUG_
#if defined(_TZL_DEBUG_) && defined(TZL_MEOW)
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define ull unsigned long long
#define rep(i,x,y,z) for(int i=(x),i##misaka=(y);i<=i##misaka;i+=(z))
#define per(i,x,y,z) for(int i=(x),i##mik0t0=(y);i>=i##mik0t0;i-=(z))
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define i128 __int128
#define _1 first
#define _2 second
#define ld long double
#define cint const int
#define pcnt __builtin_popcountll
#define vint vector<int>
#define vpii vector<pair<int,int> >
using namespace std;

const int inf=(sizeof(int)==4?0x3f3f3f3f:0x3f3f3f3f3f3f3f3f);
const int mod=1e9+7;
const long double EPS=1e-7;
const int maxn=2200;
int gcd(int a,int b){
	if(!a || !b)	return a+b;
	unsigned az=__builtin_ctzll(a),bz=__builtin_ctzll(b);unsigned z=min(az,bz);b>>=bz;
	while(a){	a>>=az;int d=a-b;az=__builtin_ctzll(d),b=min(a,b),a=(d<0?-d:d);}
	return b<<z;
}
template<typename T>void chkmin(T& x,const T& y){return y<x?(x=y,void()):void();}
template<typename T>void chkmax(T& x,const T& y){return x<y?(x=y,void()):void();}
bool Mbe;
void inc(int &x,int y){	x=(x+y>=mod?x+y-mod:x+y);}
void dec(int &x,int y){	x=(x-y<0?x-y+mod:x-y);}
int mul(vint vec){int ans=1;for(auto x:vec)	ans*=x,ans%=mod;return ans;}

int fac[maxn],finv[maxn];
ll fpow(ll x,int y){
	ll rt=1;
	for(;y;y>>=1,x=1ll*x*x%mod) if(y&1) rt=1ll*rt*x%mod;
	return rt;
}int inv(int x){	return fpow(x,mod-2);}
void init(int n){
#if 1
	fac[0]=fac[1]=1;finv[0]=finv[1]=1;
	rep(i,2,n,1){	fac[i]=1ll*fac[i-1]*i%mod;}finv[n]=inv(fac[n]);
	per(i,n-1,1,1){	finv[i]=1ll*finv[i+1]*(i+1)%mod;}
#endif
}int C(int n,int m){
	if(n<m || n<0 || m<0)	return 0;
	return 1ll*fac[n]*finv[m]%mod*finv[n-m]%mod;
}

int w[maxn];
int f[maxn][maxn][3];
int sa[maxn];

bool Med;
signed main()
{ios::sync_with_stdio(0);cin.tie(0);init(maxn-1);cerr<<fixed<<setprecision(3)<<(&Mbe-&Med)/1048576.0<<"MiB"<<endl;
	int n;
	while(cin>>n){
		rep(i,1,n,1)	cin>>w[i];
		rep(i,0,n,1)	rep(j,0,n,1)	rep(k,0,2,1)	f[i][j][k]=0;
		rep(v,1,n,1)	f[1][v][0]=w[v],f[1][v][1]=w[v]*(v-1)%mod,f[1][v][2]=w[v]*(v-1)%mod*(v-1)%mod;
		rep(i,1,n-2,1){
			int pr=0;
			rep(v,0,n+1,1)	sa[v]=0;
			per(v,n,1,1)	sa[v]=sa[v+1]+f[i-1][v][0],sa[v]%=mod; 
			rep(v,1,n,1){
				
				if(i!=1){
					inc(f[i][v][2],pr);
					inc(f[i][v][0],sa[v]);
					inc(f[i][v][1],sa[v]*(v-1)%mod);
					inc(f[i][v][2],sa[v]*(v-1)%mod*(v-1)%mod);
					rep(j,0,2,1)	f[i][v][j]*=w[v],f[i][v][j]%=mod;
				}
				
				inc(f[i+1][v][0],f[i][v][1]);inc(f[i+1][v][1],f[i][v][2]);
				
				pr+=(f[i-1][v][1]*v%mod+f[i-1][v][2])%mod+f[i-1][v][0]*v%mod*v%mod;pr%=mod;
			}
		}
		int ans=0;	
		rep(v,1,n,1)	inc(ans,f[n-2][v][0]*(v)%mod*(v)%mod),inc(ans,f[n-2][v][1]*(v)%mod),inc(ans,f[n-2][v][2]);
		ans%=mod;
		cout<<ans<<endl;
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3876kb

input:

3
1 2 3
4
1 1 1 1

output:

72
256

result:

ok 2 number(s): "72 256"

Test #2:

score: 0
Accepted
time: 2ms
memory: 6012kb

input:

20
2 1 1 2 1 1 2 2 1 1 1 2 1 2 2 2 2 2 1 1
20
1 1 1 1 1 1 1 2 2 2 2 1 2 1 2 1 1 1 2 2
20
2 1 2 2 1 2 2 1 1 1 2 1 2 1 2 2 1 1 2 1
20
1 1 1 1 1 2 1 1 1 2 1 2 2 1 1 2 2 2 1 2
20
2 2 1 1 2 2 2 1 2 2 1 2 2 2 2 1 2 2 2 2
20
1 1 2 1 2 1 2 2 1 2 2 2 1 2 1 2 2 2 1 1
20
1 2 1 1 1 2 1 1 1 1 1 2 1 2 1 1 2 2 2 1...

output:

319733964
40518147
400924261
38787721
897349820
493064982
759767625
401417778
567673098
202982388
409477312
214563090
608955253
887076718
443657041
235173408
471938201
768115792
934580672
588618862
808662651
462080423
871122184
321300347
413884324
720362807
549790197
780388163
250729956
49025886
263...

result:

ok 100 numbers

Test #3:

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

input:

20
983380751 708372152 534389660 854380310 406905313 606185721 941692711 734994736 910390968 900300887 183918461 371552529 798892008 68293780 650769940 547768169 502245417 567965812 623465221 632455730
20
969814296 632645698 353407887 775111974 19835316 622749258 218528404 235697220 677299937 151257...

output:

901128997
908372962
843262444
477210532
825370959
861748183
818296926
567410118
495019857
123498731
723176529
841859717
213644035
845439384
489145021
750276499
460768856
443673849
909615746
996576192
181226793
394196473
806760075
394894275
961660067
359733606
645650813
957584478
290217414
160017286
...

result:

ok 100 numbers

Test #4:

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

input:

50
546326159 188010383 744080796 970371898 707879921 337976248 218468964 271634902 363822839 142649550 74624041 695797688 16056713 122318400 445551499 511751832 358582430 495733936 591190909 610584228 125744325 544261750 202395079 2630396 345195167 148750363 990265221 239686197 583270754 451628256 8...

output:

953472132
176277811
817755515
345600464
71009615
636715799
672096907
783602797
527280447
638297563
725540036
674573744
271472152
563761119
393445571
696033139
495478492
390457147
698571984
18175901
60734091
368367517
655107436
934986143
808192747
55862567
896507513
532862866
212425116
218271513
4785...

result:

ok 40 numbers

Test #5:

score: 0
Accepted
time: 19ms
memory: 30868kb

input:

500
923289363 281790836 394996448 3461119 297656725 85160318 333917012 944579859 277222705 364228860 657772876 476918464 201589281 374257316 459651358 361386596 254071925 732085023 324787251 775459986 520545937 132229513 639843210 956102033 228591021 59772402 102435380 277235675 864305236 752164831 ...

output:

547107559
173944705
96178102
358654284

result:

ok 4 number(s): "547107559 173944705 96178102 358654284"

Test #6:

score: 0
Accepted
time: 84ms
memory: 107480kb

input:

2000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

596636543

result:

ok 1 number(s): "596636543"

Test #7:

score: 0
Accepted
time: 78ms
memory: 107520kb

input:

2000
1 2 2 2 1 2 1 1 1 1 1 1 2 1 1 2 2 2 1 2 2 2 2 1 1 1 1 2 2 2 2 2 2 1 2 1 1 1 1 1 1 1 2 2 2 2 2 2 1 2 1 2 1 2 2 1 1 2 2 2 1 1 2 1 1 2 2 2 1 2 2 2 2 1 1 1 1 2 2 2 2 2 1 2 1 1 1 2 1 2 2 1 2 1 2 2 2 1 2 1 1 1 2 2 2 2 1 1 2 1 2 1 1 2 1 2 1 1 1 1 1 2 2 2 1 1 2 2 1 2 1 2 1 1 2 1 1 1 2 1 1 1 2 2 2 2 2 1...

output:

60361314

result:

ok 1 number(s): "60361314"

Test #8:

score: 0
Accepted
time: 79ms
memory: 109060kb

input:

2000
1 2 1 1 2 2 2 3 1 3 2 3 2 2 3 1 2 1 3 1 3 2 2 2 2 3 3 3 2 3 1 2 2 1 3 2 3 1 3 3 2 1 2 2 2 2 3 1 3 1 2 2 3 3 1 2 1 1 3 2 2 2 2 2 1 2 1 1 2 2 1 2 2 2 1 1 3 1 2 2 3 3 3 1 2 2 1 2 3 3 3 1 2 1 2 1 2 2 2 3 2 1 3 3 3 1 3 2 2 1 1 1 1 1 3 2 1 2 3 2 3 3 1 1 3 3 3 2 2 1 1 3 1 2 3 1 2 3 1 1 2 3 2 1 1 2 1 2...

output:

846447792

result:

ok 1 number(s): "846447792"

Test #9:

score: 0
Accepted
time: 72ms
memory: 108672kb

input:

2000
1 3 1 3 1 3 4 3 2 1 4 2 4 4 1 4 1 2 3 4 3 4 3 1 3 3 4 2 1 4 3 3 2 2 3 1 4 2 2 2 2 2 2 3 2 3 1 4 1 1 2 4 2 3 2 2 3 4 4 1 2 4 4 1 1 4 4 3 3 2 2 1 1 3 3 4 1 2 4 4 3 4 4 4 3 2 3 3 4 1 2 4 1 3 4 3 2 3 2 1 3 1 4 4 1 4 3 1 3 2 1 1 3 3 3 4 2 2 2 1 4 2 2 3 2 3 2 1 1 3 3 4 2 1 1 4 4 1 4 3 3 2 4 1 1 3 1 1...

output:

665904082

result:

ok 1 number(s): "665904082"

Test #10:

score: 0
Accepted
time: 94ms
memory: 107560kb

input:

2000
2 3 1 5 2 3 3 2 2 5 5 2 1 4 2 1 2 1 5 2 5 2 5 2 1 3 4 5 5 1 4 3 4 1 1 4 3 4 4 2 3 3 1 4 3 4 3 3 3 1 5 5 1 2 5 2 4 4 2 4 1 3 3 5 2 3 2 2 3 2 3 4 4 1 1 1 2 3 1 1 3 4 1 4 5 5 4 3 5 5 5 2 2 1 2 1 3 3 5 5 2 4 1 5 3 3 5 1 2 5 4 3 5 2 1 1 4 5 3 1 3 4 2 4 5 4 5 3 3 4 1 4 2 2 4 2 3 1 4 3 1 5 5 1 4 4 4 3...

output:

469569800

result:

ok 1 number(s): "469569800"

Test #11:

score: 0
Accepted
time: 77ms
memory: 107280kb

input:

2000
4 2 2 1 4 3 1 3 3 4 3 5 5 6 3 5 6 1 1 3 2 5 3 6 5 2 2 4 6 1 5 2 2 2 5 3 4 6 1 5 4 1 2 6 3 4 4 6 3 2 2 1 2 4 4 1 4 6 4 3 6 2 5 6 1 1 4 1 2 2 4 6 3 4 4 6 6 4 6 2 4 4 2 1 5 6 5 6 1 5 4 3 5 1 2 1 1 2 6 6 3 2 5 2 6 6 4 3 4 5 2 2 3 2 1 2 6 3 4 2 1 5 2 1 6 3 1 1 2 1 4 3 6 2 4 5 6 2 4 2 6 3 2 5 5 3 5 4...

output:

750570608

result:

ok 1 number(s): "750570608"

Test #12:

score: 0
Accepted
time: 82ms
memory: 108432kb

input:

2000
1 3 1 4 6 7 2 2 3 1 2 6 4 2 6 5 1 1 4 3 7 7 1 6 4 6 3 2 5 7 5 4 1 6 7 3 1 7 7 5 5 2 3 1 7 4 5 3 4 3 1 3 4 1 4 6 6 7 1 6 2 3 6 2 6 1 7 6 3 2 1 7 1 7 4 3 1 1 2 1 4 6 5 3 3 7 3 1 1 4 1 4 1 4 1 4 5 3 5 2 6 6 2 1 5 6 5 2 6 5 4 7 2 3 3 7 1 7 5 7 4 5 1 3 3 6 1 5 5 6 2 2 7 1 6 7 7 4 2 2 4 2 6 7 6 7 1 5...

output:

271631582

result:

ok 1 number(s): "271631582"

Test #13:

score: 0
Accepted
time: 82ms
memory: 107928kb

input:

2000
6 4 8 6 3 2 5 3 4 2 6 5 1 1 5 1 7 7 7 3 5 3 8 2 7 4 4 2 7 1 7 8 7 3 6 2 7 6 4 5 5 4 6 5 8 1 7 8 5 8 5 3 3 4 2 4 6 8 4 6 7 8 5 8 2 6 3 6 6 6 1 6 1 2 5 5 2 6 8 8 5 5 1 3 3 2 2 5 7 8 1 2 1 3 1 8 7 5 6 2 7 2 5 8 7 4 1 5 6 7 7 8 8 6 3 4 5 4 1 7 2 4 5 6 6 2 3 8 7 8 8 7 3 2 6 2 7 2 4 6 4 4 4 8 4 3 4 4...

output:

317633495

result:

ok 1 number(s): "317633495"

Test #14:

score: 0
Accepted
time: 94ms
memory: 109100kb

input:

2000
4 5 7 1 2 4 1 8 3 1 3 2 7 3 2 2 7 4 4 9 1 6 3 4 4 2 4 7 8 3 3 9 7 1 3 4 6 7 5 3 6 5 3 4 4 3 3 5 4 1 9 8 5 8 9 1 4 5 8 2 3 3 9 5 5 1 3 9 7 7 3 7 3 4 5 3 6 2 3 1 8 9 1 2 5 1 5 2 5 9 4 6 2 8 5 1 3 8 8 3 6 7 7 2 8 6 9 8 8 9 2 3 6 6 8 5 9 7 2 8 7 4 8 5 7 1 5 4 7 3 6 1 5 9 6 5 6 9 1 9 2 2 1 7 9 2 6 9...

output:

997354671

result:

ok 1 number(s): "997354671"

Test #15:

score: 0
Accepted
time: 90ms
memory: 108964kb

input:

2000
5 2 5 1 3 3 1 6 6 7 8 1 3 9 6 2 8 1 10 10 1 2 4 7 9 5 8 6 10 5 9 10 2 4 7 9 4 7 6 9 5 2 4 1 10 9 7 8 10 1 10 8 3 7 2 2 10 8 10 4 2 10 6 4 1 7 8 9 5 5 5 1 1 4 1 9 3 4 3 2 8 2 10 10 7 3 4 6 1 2 3 8 1 1 10 3 10 4 1 5 2 1 3 3 7 6 7 5 1 3 4 1 3 1 10 5 1 1 7 2 4 7 1 1 4 8 4 4 2 1 1 4 7 5 1 5 1 4 8 4 ...

output:

436029916

result:

ok 1 number(s): "436029916"

Extra Test:

score: 0
Extra Test Passed