QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#762379#8023. The Journey of Geor AutumnyhdddAC ✓196ms316360kbC++141.4kb2024-11-19 14:47:252024-11-19 14:47:32

Judging History

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

  • [2024-11-19 14:47:32]
  • 评测
  • 测评结果:AC
  • 用时:196ms
  • 内存:316360kb
  • [2024-11-19 14:47:25]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define db double
using namespace std;
const int maxn=10000010;
const int inf=1e18;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
	return x*f;
}
bool Mbe;

int n,k,sum;
int dp[maxn];
int fac[maxn],inv[maxn],ni[maxn];
inline int ksm(int a,int b=mod-2){
	int ans=1;
	while(b){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
int C(int m,int n){
	if(m<n||m<0||n<0)return 0;
	return fac[m]*inv[n]%mod*inv[m-n]%mod;
}
void work(){
	n=read(),k=read();
	fac[0]=1;for(int i=1;i<=n;i++)fac[i]=fac[i-1]*i%mod;
	inv[n]=ksm(fac[n]);for(int i=n-1;~i;i--)inv[i]=inv[i+1]*(i+1)%mod;
	for(int i=1;i<=n;i++)ni[i]=fac[i-1]*inv[i]%mod;
	dp[0]=1;sum=fac[n-1];
	for(int i=1;i<=n;i++){
		if(i>=k){
			(sum+=mod-dp[i-k-1]*fac[n-(i-k-1)-1]%mod)%=mod;
		}
		dp[i]=sum*inv[n-i]%mod;
		(sum+=dp[i]*fac[n-i-1])%=mod;
	}
	printf("%lld\n",dp[n]);
}

// \
444

bool Med;
int T;
signed main(){
	// freopen("b.in","r",stdin);
	// freopen("b.out","w",stdout);
	
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	
//	cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
	
	T=1;
	while(T--)work();
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

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

input:

1 1

output:

1

result:

ok "1"

Test #2:

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

input:

1 2

output:

1

result:

ok "1"

Test #3:

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

input:

1 3

output:

1

result:

ok "1"

Test #4:

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

input:

1 4

output:

1

result:

ok "1"

Test #5:

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

input:

2 1

output:

1

result:

ok "1"

Test #6:

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

input:

2 2

output:

2

result:

ok "2"

Test #7:

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

input:

2 3

output:

2

result:

ok "2"

Test #8:

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

input:

2 4

output:

2

result:

ok "2"

Test #9:

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

input:

3 1

output:

1

result:

ok "1"

Test #10:

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

input:

3 2

output:

4

result:

ok "4"

Test #11:

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

input:

3 3

output:

6

result:

ok "6"

Test #12:

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

input:

3 4

output:

6

result:

ok "6"

Test #13:

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

input:

4 1

output:

1

result:

ok "1"

Test #14:

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

input:

4 2

output:

10

result:

ok "10"

Test #15:

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

input:

4 3

output:

18

result:

ok "18"

Test #16:

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

input:

4 4

output:

24

result:

ok "24"

Test #17:

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

input:

99 50

output:

955866606

result:

ok "955866606"

Test #18:

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

input:

99 70

output:

296999003

result:

ok "296999003"

Test #19:

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

input:

1034 998

output:

637688669

result:

ok "637688669"

Test #20:

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

input:

1099 997

output:

712935289

result:

ok "712935289"

Test #21:

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

input:

10314 998

output:

224695890

result:

ok "224695890"

Test #22:

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

input:

10929 9974

output:

160291286

result:

ok "160291286"

Test #23:

score: 0
Accepted
time: 4ms
memory: 12244kb

input:

103124 99448

output:

695932649

result:

ok "695932649"

Test #24:

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

input:

109139 9937

output:

268916696

result:

ok "268916696"

Test #25:

score: 0
Accepted
time: 15ms
memory: 42920kb

input:

1031234 99238

output:

441457721

result:

ok "441457721"

Test #26:

score: 0
Accepted
time: 13ms
memory: 44112kb

input:

1091239 991237

output:

61047495

result:

ok "61047495"

Test #27:

score: 0
Accepted
time: 183ms
memory: 316360kb

input:

10000000 9982443

output:

224744113

result:

ok "224744113"

Test #28:

score: 0
Accepted
time: 196ms
memory: 316352kb

input:

9999977 5678901

output:

641748125

result:

ok "641748125"

Extra Test:

score: 0
Extra Test Passed