QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#624241 | #8023. The Journey of Geor Autumn | zth | WA | 101ms | 161872kb | C++20 | 904b | 2024-10-09 15:19:02 | 2024-10-09 15:19:02 |
Judging History
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]+fac[i-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";
}
详细
Test #1:
score: 100
Accepted
time: 75ms
memory: 160980kb
input:
1 1
output:
1
result:
ok "1"
Test #2:
score: 0
Accepted
time: 85ms
memory: 161416kb
input:
1 2
output:
1
result:
ok "1"
Test #3:
score: 0
Accepted
time: 71ms
memory: 161048kb
input:
1 3
output:
1
result:
ok "1"
Test #4:
score: 0
Accepted
time: 83ms
memory: 159996kb
input:
1 4
output:
1
result:
ok "1"
Test #5:
score: 0
Accepted
time: 86ms
memory: 161080kb
input:
2 1
output:
1
result:
ok "1"
Test #6:
score: 0
Accepted
time: 79ms
memory: 160940kb
input:
2 2
output:
2
result:
ok "2"
Test #7:
score: 0
Accepted
time: 81ms
memory: 160036kb
input:
2 3
output:
2
result:
ok "2"
Test #8:
score: 0
Accepted
time: 90ms
memory: 161264kb
input:
2 4
output:
2
result:
ok "2"
Test #9:
score: 0
Accepted
time: 101ms
memory: 160616kb
input:
3 1
output:
1
result:
ok "1"
Test #10:
score: 0
Accepted
time: 91ms
memory: 161832kb
input:
3 2
output:
4
result:
ok "4"
Test #11:
score: 0
Accepted
time: 91ms
memory: 161872kb
input:
3 3
output:
6
result:
ok "6"
Test #12:
score: 0
Accepted
time: 85ms
memory: 160432kb
input:
3 4
output:
6
result:
ok "6"
Test #13:
score: 0
Accepted
time: 90ms
memory: 159956kb
input:
4 1
output:
1
result:
ok "1"
Test #14:
score: 0
Accepted
time: 101ms
memory: 160916kb
input:
4 2
output:
10
result:
ok "10"
Test #15:
score: -100
Wrong Answer
time: 75ms
memory: 161632kb
input:
4 3
output:
24
result:
wrong answer 1st words differ - expected: '18', found: '24'