QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#19827#1810. Generate the Sequencesconqueror_of_zky#WA 74ms3872kbC++141.5kb2022-02-11 17:32:532022-05-06 07:14:41

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-06 07:14:41]
  • 评测
  • 测评结果:WA
  • 用时:74ms
  • 内存:3872kb
  • [2022-02-11 17:32:53]
  • 提交

answer

#include <bits/stdc++.h>
//#define int long long
#define ll long long
#define db double
#define fi first
#define se second
#define pii pair<int,int>
#define vi vector<int>

using namespace std;
const int mod=998244353; 
const int maxn=5e3; 
void add(int &x,int y){
	x+=y;
	if (x>=mod) x-=mod; 
}
int n,m,inv[maxn+5],fac[maxn+5],ivf[maxn+5],f[maxn+5][2]; 
vi F; 
int len; 
int C(int x,int y) {
	if (x<y) return 0;
	if (x<=maxn) return 1ll*fac[x]*ivf[x-y]%mod*ivf[y]%mod; 
	int ret=1; 
	for (int j=1;j<=y;j++) {
		ret=1ll*ret*(x-j+1)%mod;
		ret=1ll*ret*inv[j]%mod;
	}
	return ret; 
} 
void prework() {
	inv[1]=1; 
	for (int i=2;i<=maxn;i++) {
		inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod; 
	}
	fac[0]=1; ivf[0]=1;
	for (int i=1;i<=maxn;i++) fac[i]=1ll*fac[i-1]*i%mod;
	for (int i=1;i<=maxn;i++) ivf[i]=1ll*ivf[i-1]*inv[i]%mod;
} 
int main() {
	prework();
	scanf("%d %d",&n,&m);
	n++;
	len=min(n,m); 
	F.resize(len+1); 
	for (int i=3;i<=len;i++) {
		F[i]=C(m-2,i-2); 
	}
    f[n][0]=f[n][1]=1;
    for (int i=n-1;i>=1;i--) {
    		add(f[i][0],f[i+1][1]); 
    		add(f[i][1],f[i+1][0]); 
    		add(f[i][1],f[i+1][1]); 
    		add(f[i][0],f[i+1][0]); 
    	//	cout<<i<<' '<<j<<' '<<f[i][j]<<'\n'; 
    		for (int k=i+2;k<=n;k++) {
    			add(f[i][0],1ll*f[k][1]*F[k-i+1]%mod*C(n-i-1,n-k)%mod*fac[k-i-1]%mod); 
    			add(f[i][1],1ll*f[k][0]*F[k-i+1]%mod*C(n-i-1,n-k)%mod*fac[k-i-1]%mod); 
			}
	//	}
	//	cout<<f[i]<<'\n'; 
	}
	printf("%d\n",f[1][0]); 
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3836kb

input:

2 3

output:

5

result:

ok answer is '5'

Test #2:

score: 0
Accepted
time: 17ms
memory: 3860kb

input:

1024 52689658

output:

654836147

result:

ok answer is '654836147'

Test #3:

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

input:

1 2

output:

2

result:

ok answer is '2'

Test #4:

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

input:

1 3

output:

2

result:

ok answer is '2'

Test #5:

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

input:

1 100000000

output:

2

result:

ok answer is '2'

Test #6:

score: 0
Accepted
time: 1ms
memory: 3828kb

input:

2 2

output:

4

result:

ok answer is '4'

Test #7:

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

input:

2 4

output:

6

result:

ok answer is '6'

Test #8:

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

input:

2 5

output:

7

result:

ok answer is '7'

Test #9:

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

input:

2 100000000

output:

100000002

result:

ok answer is '100000002'

Test #10:

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

input:

3 2

output:

8

result:

ok answer is '8'

Test #11:

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

input:

3 3

output:

14

result:

ok answer is '14'

Test #12:

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

input:

3 4

output:

22

result:

ok answer is '22'

Test #13:

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

input:

3 5

output:

32

result:

ok answer is '32'

Test #14:

score: 0
Accepted
time: 1ms
memory: 3868kb

input:

3 100000000

output:

446563791

result:

ok answer is '446563791'

Test #15:

score: -100
Wrong Answer
time: 74ms
memory: 3840kb

input:

3000 2

output:

265657438

result:

wrong answer expected '21292722', found '265657438'