QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#616236 | #8023. The Journey of Geor Autumn | Soestx | WA | 0ms | 3716kb | C++23 | 1.1kb | 2024-10-05 23:46:35 | 2024-10-05 23:46:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pll pair<int,int>
#define fi first
#define se second
typedef long long LL;
typedef unsigned long long ull;
typedef long double ld;
int n,m,k;
const int N=1e3+10,M=5e3,mod=998244353,inf=1e18;
const double eps=1e-8;
int res,cnt;
int dp[N],sum[N];
int fac[N],ifa[N];
int qpow(int a,int b)
{
int res=1;
while(b)
{
if(b&1) res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res;
}
void ini()
{
fac[0]=1;
for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
ifa[n]=qpow(fac[n],mod-2);
for(int i=n-1;i>=0;i--)
{
ifa[i]=ifa[i+1]*(i+1)%mod;
}
}
void solve() {
cin>>n>>k;
ini();
dp[0]=1;
sum[0]=dp[0];
for(int i=1;i<=n;i++)
{
if(i-1>=k)
{
dp[i]=(sum[i-1]-sum[i-1-k]+mod)%mod;
}
else dp[i]=sum[i-1];
dp[i]=dp[i]*fac[i-1]%mod;
sum[i]=(sum[i-1]+dp[i]*ifa[i]%mod)%mod;
}
cout<<dp[n]<<endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T=1;
//cin>>T;
while(T--)solve();
return 0;
}
/*
1
17 8
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3516kb
input:
1 1
output:
1
result:
ok "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
1 2
output:
1
result:
ok "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
1 3
output:
1
result:
ok "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
1 4
output:
1
result:
ok "1"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
2 1
output:
1
result:
ok "1"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3716kb
input:
2 2
output:
2
result:
ok "2"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
2 3
output:
2
result:
ok "2"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
2 4
output:
2
result:
ok "2"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
3 1
output:
1
result:
ok "1"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
3 2
output:
4
result:
ok "4"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
3 3
output:
6
result:
ok "6"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
3 4
output:
6
result:
ok "6"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
4 1
output:
1
result:
ok "1"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
4 2
output:
10
result:
ok "10"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
4 3
output:
18
result:
ok "18"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
4 4
output:
24
result:
ok "24"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
99 50
output:
955866606
result:
ok "955866606"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
99 70
output:
296999003
result:
ok "296999003"
Test #19:
score: -100
Wrong Answer
time: 0ms
memory: 3700kb
input:
1034 998
output:
100100217
result:
wrong answer 1st words differ - expected: '637688669', found: '100100217'