QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#762927 | #8023. The Journey of Geor Autumn | georgeyucjr | AC ✓ | 191ms | 316164kb | C++17 | 1.4kb | 2024-11-19 17:19:08 | 2024-11-19 17:19:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std; using ll = long long; using ull = unsigned long long; using i128 = __int128_t; using u128 = unsigned __int128_t; using pii = pair<int, int>;
#define rep(i, f, t, ...) for (int i = f, ##__VA_ARGS__; i <= t; ++i)
#define per(i, f, t, ...) for (int i = f, ##__VA_ARGS__; i >= t; --i)
#define eb emplace_back
#define ALL(x) x.begin(), x.end()
#define FILEIO(fn) freopen(fn".in", "r", stdin), freopen(fn".out", "w", stdout)
template < typename T > inline int SZ(T &&t) { return t.size(); }
constexpr ll mod = 998244353; inline void chkmod(ll &x) { if (x >= mod) x -= mod; } inline ll afteradd(const ll &x) { return x >= mod ? x - mod : x; } inline ll Add(const ll&x, const ll &y) { return (x + y >= mod) ? x + y - mod : x + y; }
constexpr int N = 1e7 + 5;
int n, k; ll fac[N], ifac[N], dp[N], inv[N], ans=0;
ll qpow(ll x, int y) {
ll res = 1;
while (y) {
if (y & 1) {
(res *= x) %= mod;
}
(x *= x) %= mod;
y >>= 1;
}
return res;
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin>>n>>k;fac[0]=1;rep(i,1,N-5)fac[i]=fac[i-1]*i%mod;ifac[N-5]=qpow(fac[N-5],mod-2);per(i,N-5,1)ifac[i-1]=ifac[i]*i%mod;rep(i,1,N-5)inv[i]=ifac[i]*fac[i-1]%mod;
if(k>=n)return cout<<fac[n]<<"\n",0;dp[0]=1;rep(i,1,n-1){
dp[i]=dp[i-1];if(i-k>=1)chkmod(dp[i]+=mod-dp[i-k-1]);(dp[i]*=inv[n-i])%=mod;
if(i>=n-k)chkmod(ans+=fac[n-1]*dp[i]%mod);chkmod(dp[i]+=dp[i-1]);
}cout<<ans<<"\n";return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 83ms
memory: 237976kb
input:
1 1
output:
1
result:
ok "1"
Test #2:
score: 0
Accepted
time: 112ms
memory: 238048kb
input:
1 2
output:
1
result:
ok "1"
Test #3:
score: 0
Accepted
time: 108ms
memory: 238096kb
input:
1 3
output:
1
result:
ok "1"
Test #4:
score: 0
Accepted
time: 91ms
memory: 238028kb
input:
1 4
output:
1
result:
ok "1"
Test #5:
score: 0
Accepted
time: 88ms
memory: 238048kb
input:
2 1
output:
1
result:
ok "1"
Test #6:
score: 0
Accepted
time: 87ms
memory: 238100kb
input:
2 2
output:
2
result:
ok "2"
Test #7:
score: 0
Accepted
time: 119ms
memory: 238100kb
input:
2 3
output:
2
result:
ok "2"
Test #8:
score: 0
Accepted
time: 104ms
memory: 237980kb
input:
2 4
output:
2
result:
ok "2"
Test #9:
score: 0
Accepted
time: 99ms
memory: 238044kb
input:
3 1
output:
1
result:
ok "1"
Test #10:
score: 0
Accepted
time: 93ms
memory: 238044kb
input:
3 2
output:
4
result:
ok "4"
Test #11:
score: 0
Accepted
time: 102ms
memory: 238056kb
input:
3 3
output:
6
result:
ok "6"
Test #12:
score: 0
Accepted
time: 84ms
memory: 238060kb
input:
3 4
output:
6
result:
ok "6"
Test #13:
score: 0
Accepted
time: 116ms
memory: 238036kb
input:
4 1
output:
1
result:
ok "1"
Test #14:
score: 0
Accepted
time: 111ms
memory: 238056kb
input:
4 2
output:
10
result:
ok "10"
Test #15:
score: 0
Accepted
time: 103ms
memory: 238096kb
input:
4 3
output:
18
result:
ok "18"
Test #16:
score: 0
Accepted
time: 91ms
memory: 237976kb
input:
4 4
output:
24
result:
ok "24"
Test #17:
score: 0
Accepted
time: 107ms
memory: 237976kb
input:
99 50
output:
955866606
result:
ok "955866606"
Test #18:
score: 0
Accepted
time: 103ms
memory: 238096kb
input:
99 70
output:
296999003
result:
ok "296999003"
Test #19:
score: 0
Accepted
time: 119ms
memory: 237996kb
input:
1034 998
output:
637688669
result:
ok "637688669"
Test #20:
score: 0
Accepted
time: 89ms
memory: 238052kb
input:
1099 997
output:
712935289
result:
ok "712935289"
Test #21:
score: 0
Accepted
time: 99ms
memory: 238132kb
input:
10314 998
output:
224695890
result:
ok "224695890"
Test #22:
score: 0
Accepted
time: 98ms
memory: 238176kb
input:
10929 9974
output:
160291286
result:
ok "160291286"
Test #23:
score: 0
Accepted
time: 93ms
memory: 238792kb
input:
103124 99448
output:
695932649
result:
ok "695932649"
Test #24:
score: 0
Accepted
time: 95ms
memory: 238892kb
input:
109139 9937
output:
268916696
result:
ok "268916696"
Test #25:
score: 0
Accepted
time: 79ms
memory: 246080kb
input:
1031234 99238
output:
441457721
result:
ok "441457721"
Test #26:
score: 0
Accepted
time: 91ms
memory: 246564kb
input:
1091239 991237
output:
61047495
result:
ok "61047495"
Test #27:
score: 0
Accepted
time: 157ms
memory: 316160kb
input:
10000000 9982443
output:
224744113
result:
ok "224744113"
Test #28:
score: 0
Accepted
time: 191ms
memory: 316164kb
input:
9999977 5678901
output:
641748125
result:
ok "641748125"
Extra Test:
score: 0
Extra Test Passed