QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#762613 | #8023. The Journey of Geor Autumn | DEMONKILLER | AC ✓ | 218ms | 123004kb | C++20 | 1.4kb | 2024-11-19 15:48:51 | 2024-11-19 15:48:53 |
Judging History
answer
#include<bits/stdc++.h>
#define N 10000010
#define Pii pair<int,int>
#define Fi first
#define Se second
#define ll long long
#define ull unsigned long long
#define lb(i) i&(-i)
#define lc p<<1
#define rc p<<1|1
using namespace std;
namespace IO{
#define SIZE (1<<21)
#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[SIZE],*p1=buf,*p2=buf;
inline bool Isdigit(char c){return c>='0'&&c<='9';}
template <typename T>inline void read(T& r){
r=0;bool w=0;char ch=getchar();
while(!Isdigit(ch))w=ch=='-'?1:0,ch=getchar();
while(Isdigit(ch))r=(r<<3)+(r<<1)+(ch^48),ch=getchar();
r=w?-r:r;
}
template<typename T,typename ...Args>
void read(T &x,Args &...args){read(x),read(args...);}
#undef SIZE
}
using namespace IO;
const int Mod=998244353;
int Qpow(int a,int b){
int Res=1;
while(b){
if(b&1)Res=1LL*Res*a%Mod;
a=1LL*a*a%Mod;
b>>=1;
}
return Res;
}
int n,K,Sum,f[N],inv[N],fac[N];
void Init(int n){
fac[0]=fac[1]=1;
for(int i=2;i<=n;i++)
fac[i]=1LL*fac[i-1]*i%Mod;
inv[n]=Qpow(fac[n],Mod-2);
for(int i=n;i>=1;i--)
inv[i-1]=1LL*inv[i]*i%Mod;
}
int main(){
Init(N-10);
read(n,K);
f[0]=1,Sum=fac[n-1];
for(int i=1;i<=n;i++){
f[i]=1LL*Sum*inv[n-i]%Mod;
if(i<n){
(Sum+=1LL*f[i]*fac[n-i-1]%Mod)%=Mod;
if(i>=K)Sum=(Sum-1LL*f[i-K]*fac[n-i+K-1]%Mod+Mod)%Mod;
}
}
printf("%d\n",f[n]);
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 84ms
memory: 85408kb
input:
1 1
output:
1
result:
ok "1"
Test #2:
score: 0
Accepted
time: 83ms
memory: 84084kb
input:
1 2
output:
1
result:
ok "1"
Test #3:
score: 0
Accepted
time: 95ms
memory: 84296kb
input:
1 3
output:
1
result:
ok "1"
Test #4:
score: 0
Accepted
time: 76ms
memory: 84788kb
input:
1 4
output:
1
result:
ok "1"
Test #5:
score: 0
Accepted
time: 79ms
memory: 84872kb
input:
2 1
output:
1
result:
ok "1"
Test #6:
score: 0
Accepted
time: 79ms
memory: 85524kb
input:
2 2
output:
2
result:
ok "2"
Test #7:
score: 0
Accepted
time: 79ms
memory: 84176kb
input:
2 3
output:
2
result:
ok "2"
Test #8:
score: 0
Accepted
time: 87ms
memory: 85876kb
input:
2 4
output:
2
result:
ok "2"
Test #9:
score: 0
Accepted
time: 83ms
memory: 84556kb
input:
3 1
output:
1
result:
ok "1"
Test #10:
score: 0
Accepted
time: 87ms
memory: 84712kb
input:
3 2
output:
4
result:
ok "4"
Test #11:
score: 0
Accepted
time: 87ms
memory: 84580kb
input:
3 3
output:
6
result:
ok "6"
Test #12:
score: 0
Accepted
time: 75ms
memory: 84892kb
input:
3 4
output:
6
result:
ok "6"
Test #13:
score: 0
Accepted
time: 83ms
memory: 84600kb
input:
4 1
output:
1
result:
ok "1"
Test #14:
score: 0
Accepted
time: 69ms
memory: 85000kb
input:
4 2
output:
10
result:
ok "10"
Test #15:
score: 0
Accepted
time: 82ms
memory: 84160kb
input:
4 3
output:
18
result:
ok "18"
Test #16:
score: 0
Accepted
time: 75ms
memory: 85088kb
input:
4 4
output:
24
result:
ok "24"
Test #17:
score: 0
Accepted
time: 80ms
memory: 85180kb
input:
99 50
output:
955866606
result:
ok "955866606"
Test #18:
score: 0
Accepted
time: 83ms
memory: 85484kb
input:
99 70
output:
296999003
result:
ok "296999003"
Test #19:
score: 0
Accepted
time: 80ms
memory: 84592kb
input:
1034 998
output:
637688669
result:
ok "637688669"
Test #20:
score: 0
Accepted
time: 79ms
memory: 84492kb
input:
1099 997
output:
712935289
result:
ok "712935289"
Test #21:
score: 0
Accepted
time: 71ms
memory: 86072kb
input:
10314 998
output:
224695890
result:
ok "224695890"
Test #22:
score: 0
Accepted
time: 87ms
memory: 84332kb
input:
10929 9974
output:
160291286
result:
ok "160291286"
Test #23:
score: 0
Accepted
time: 77ms
memory: 86096kb
input:
103124 99448
output:
695932649
result:
ok "695932649"
Test #24:
score: 0
Accepted
time: 81ms
memory: 84788kb
input:
109139 9937
output:
268916696
result:
ok "268916696"
Test #25:
score: 0
Accepted
time: 95ms
memory: 89020kb
input:
1031234 99238
output:
441457721
result:
ok "441457721"
Test #26:
score: 0
Accepted
time: 92ms
memory: 88872kb
input:
1091239 991237
output:
61047495
result:
ok "61047495"
Test #27:
score: 0
Accepted
time: 206ms
memory: 121612kb
input:
10000000 9982443
output:
224744113
result:
ok "224744113"
Test #28:
score: 0
Accepted
time: 218ms
memory: 123004kb
input:
9999977 5678901
output:
641748125
result:
ok "641748125"
Extra Test:
score: 0
Extra Test Passed