QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#624388#8023. The Journey of Geor AutumnzthAC ✓157ms353320kbC++20897b2024-10-09 15:44:002024-10-09 15:44:00

Judging History

This is the latest submission verdict.

  • [2024-10-09 15:44:00]
  • Judged
  • Verdict: AC
  • Time: 157ms
  • Memory: 353320kb
  • [2024-10-09 15:44:00]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll mod=998244353,MX=1e7;
ll n,k,fac[MX+5],rfac[MX+5],dp[MX+5],c[MX+5],qs[MX+5];

ll binpow(ll a, ll n) {
    ll res=1;
    while (n) {
        if (n%2) res=(res*a)%mod;
        a=(a*a)%mod;
        n/=2;
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>k;
    fac[0]=1;
    rfac[0]=1;
    for (ll i=1; i<=MX; ++i) {
        fac[i]=(fac[i-1]*i)%mod;
    }
    rfac[MX]=binpow(fac[MX],mod-2);
    for(ll i = MX - 1; i > 0;--i)
    {
        rfac[i] = rfac[i + 1] * (i + 1) % mod;
    }
    for (int i=1; i<=k; ++i) dp[i]=fac[i],qs[i]=(qs[i-1]+1)%mod;
    for (int i=k+1; i<=n; ++i) {
        dp[i]=(qs[i-1]-qs[i-k-1]+mod)%mod * fac[i-1]%mod;
        c[i]=(dp[i]*rfac[i])%mod;
        qs[i]=(qs[i-1]+c[i])%mod;
    }
    cout<<dp[n]<<"\n";
}

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

详细

Test #1:

score: 100
Accepted
time: 85ms
memory: 163652kb

input:

1 1

output:

1

result:

ok "1"

Test #2:

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

input:

1 2

output:

1

result:

ok "1"

Test #3:

score: 0
Accepted
time: 88ms
memory: 161940kb

input:

1 3

output:

1

result:

ok "1"

Test #4:

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

input:

1 4

output:

1

result:

ok "1"

Test #5:

score: 0
Accepted
time: 80ms
memory: 165596kb

input:

2 1

output:

1

result:

ok "1"

Test #6:

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

input:

2 2

output:

2

result:

ok "2"

Test #7:

score: 0
Accepted
time: 76ms
memory: 163664kb

input:

2 3

output:

2

result:

ok "2"

Test #8:

score: 0
Accepted
time: 80ms
memory: 163504kb

input:

2 4

output:

2

result:

ok "2"

Test #9:

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

input:

3 1

output:

1

result:

ok "1"

Test #10:

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

input:

3 2

output:

4

result:

ok "4"

Test #11:

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

input:

3 3

output:

6

result:

ok "6"

Test #12:

score: 0
Accepted
time: 89ms
memory: 163532kb

input:

3 4

output:

6

result:

ok "6"

Test #13:

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

input:

4 1

output:

1

result:

ok "1"

Test #14:

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

input:

4 2

output:

10

result:

ok "10"

Test #15:

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

input:

4 3

output:

18

result:

ok "18"

Test #16:

score: 0
Accepted
time: 76ms
memory: 162728kb

input:

4 4

output:

24

result:

ok "24"

Test #17:

score: 0
Accepted
time: 85ms
memory: 164204kb

input:

99 50

output:

955866606

result:

ok "955866606"

Test #18:

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

input:

99 70

output:

296999003

result:

ok "296999003"

Test #19:

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

input:

1034 998

output:

637688669

result:

ok "637688669"

Test #20:

score: 0
Accepted
time: 76ms
memory: 165488kb

input:

1099 997

output:

712935289

result:

ok "712935289"

Test #21:

score: 0
Accepted
time: 80ms
memory: 165564kb

input:

10314 998

output:

224695890

result:

ok "224695890"

Test #22:

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

input:

10929 9974

output:

160291286

result:

ok "160291286"

Test #23:

score: 0
Accepted
time: 88ms
memory: 166408kb

input:

103124 99448

output:

695932649

result:

ok "695932649"

Test #24:

score: 0
Accepted
time: 83ms
memory: 166948kb

input:

109139 9937

output:

268916696

result:

ok "268916696"

Test #25:

score: 0
Accepted
time: 91ms
memory: 191464kb

input:

1031234 99238

output:

441457721

result:

ok "441457721"

Test #26:

score: 0
Accepted
time: 86ms
memory: 183412kb

input:

1091239 991237

output:

61047495

result:

ok "61047495"

Test #27:

score: 0
Accepted
time: 119ms
memory: 318436kb

input:

10000000 9982443

output:

224744113

result:

ok "224744113"

Test #28:

score: 0
Accepted
time: 157ms
memory: 353320kb

input:

9999977 5678901

output:

641748125

result:

ok "641748125"

Extra Test:

score: 0
Extra Test Passed