QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#432956#8023. The Journey of Geor Autumnwsc2008#AC ✓164ms238184kbC++141.3kb2024-06-07 21:16:472024-06-07 21:16:48

Judging History

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

  • [2024-06-07 21:16:48]
  • 评测
  • 测评结果:AC
  • 用时:164ms
  • 内存:238184kb
  • [2024-06-07 21:16:47]
  • 提交

answer

#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
bool Mbe;
ll read(){
    ll 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*10+ch-'0';ch=getchar();}
    return x*f;
}
void write(ll x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
const ll N=1e7+9,Mod=998244353;
ll n,k,dp[N],fac[N],ifac[N];
ll pw(ll x,ll p){
    ll res=1;
    while(p){
        if(p&1)res=res*x%Mod;
        x=x*x%Mod;
        p>>=1;
    }
    return res;
}
ll C(ll x,ll y){
    if(x<y||y<0)return 0;
    return fac[x]*ifac[y]%Mod*ifac[x-y]%Mod;
}
bool Med;
int main(){
    cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
    n=read(),k=read();
    fac[0]=1;
    rep(i,1,n)fac[i]=fac[i-1]*i%Mod;
    ifac[n]=pw(fac[n],Mod-2);
    per(i,n-1,0)ifac[i]=ifac[i+1]*(i+1)%Mod;
    rep(i,0,k)dp[i]=fac[i];
    ll s=0;
    rep(i,1,k)s=(s+dp[i]*ifac[i])%Mod;
    rep(i,k+1,n){
        dp[i]=s*fac[i-1]%Mod;
        s=(s+dp[i]*ifac[i]%Mod-dp[i-k]*ifac[i-k]%Mod+Mod)%Mod;
    }
    write(dp[n]);
    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1 1

output:

1

result:

ok "1"

Test #2:

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

input:

1 2

output:

1

result:

ok "1"

Test #3:

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

input:

1 3

output:

1

result:

ok "1"

Test #4:

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

input:

1 4

output:

1

result:

ok "1"

Test #5:

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

input:

2 1

output:

1

result:

ok "1"

Test #6:

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

input:

2 2

output:

2

result:

ok "2"

Test #7:

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

input:

2 3

output:

2

result:

ok "2"

Test #8:

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

input:

2 4

output:

2

result:

ok "2"

Test #9:

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

input:

3 1

output:

1

result:

ok "1"

Test #10:

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

input:

3 2

output:

4

result:

ok "4"

Test #11:

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

input:

3 3

output:

6

result:

ok "6"

Test #12:

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

input:

3 4

output:

6

result:

ok "6"

Test #13:

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

input:

4 1

output:

1

result:

ok "1"

Test #14:

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

input:

4 2

output:

10

result:

ok "10"

Test #15:

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

input:

4 3

output:

18

result:

ok "18"

Test #16:

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

input:

4 4

output:

24

result:

ok "24"

Test #17:

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

input:

99 50

output:

955866606

result:

ok "955866606"

Test #18:

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

input:

99 70

output:

296999003

result:

ok "296999003"

Test #19:

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

input:

1034 998

output:

637688669

result:

ok "637688669"

Test #20:

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

input:

1099 997

output:

712935289

result:

ok "712935289"

Test #21:

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

input:

10314 998

output:

224695890

result:

ok "224695890"

Test #22:

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

input:

10929 9974

output:

160291286

result:

ok "160291286"

Test #23:

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

input:

103124 99448

output:

695932649

result:

ok "695932649"

Test #24:

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

input:

109139 9937

output:

268916696

result:

ok "268916696"

Test #25:

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

input:

1031234 99238

output:

441457721

result:

ok "441457721"

Test #26:

score: 0
Accepted
time: 16ms
memory: 29396kb

input:

1091239 991237

output:

61047495

result:

ok "61047495"

Test #27:

score: 0
Accepted
time: 134ms
memory: 238184kb

input:

10000000 9982443

output:

224744113

result:

ok "224744113"

Test #28:

score: 0
Accepted
time: 164ms
memory: 238116kb

input:

9999977 5678901

output:

641748125

result:

ok "641748125"

Extra Test:

score: 0
Extra Test Passed