QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#310169 | #8023. The Journey of Geor Autumn | PetroTarnavskyi | AC ✓ | 221ms | 132584kb | C++20 | 1.4kb | 2024-01-21 06:03:37 | 2024-01-21 06:03:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); i--)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int mod = 998244353;
void updAdd(int& a, int b)
{
a += b;
if(a >= mod)
a -= mod;
}
void updSub(int& a, int b)
{
a -= b;
if(a < 0)
a += mod;
}
int mult(int a, int b)
{
return (LL) a * b % mod;
}
int binpow(int a, int n)
{
int res = 1;
while(n)
{
if(n & 1)
res = mult(res, a);
a = mult(a, a);
n /= 2;
}
return res;
}
const int N = 1.1e7;
int fact[N], ifact[N];
void init()
{
fact[0] = 1;
FOR(i, 1, N)
fact[i] = mult(fact[i - 1], i);
ifact[N - 1] = binpow(fact[N - 1], mod - 2);
RFOR(i, N, 1)
ifact[i - 1] = mult(ifact[i], i);
}
int dp[N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(15);
init();
int n, k;
cin >> n >> k;
int sum = 1;
dp[0] = 1;
FOR(i, 1, N)
{
dp[i] = mult(sum, fact[i - 1]);
updAdd(sum, mult(dp[i], ifact[i]));
if(i - k >= 0)
updSub(sum, mult(dp[i - k], ifact[i - k]));
}
cout << dp[n] << "\n";
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 188ms
memory: 132504kb
input:
1 1
output:
1
result:
ok "1"
Test #2:
score: 0
Accepted
time: 208ms
memory: 132448kb
input:
1 2
output:
1
result:
ok "1"
Test #3:
score: 0
Accepted
time: 204ms
memory: 132448kb
input:
1 3
output:
1
result:
ok "1"
Test #4:
score: 0
Accepted
time: 199ms
memory: 132532kb
input:
1 4
output:
1
result:
ok "1"
Test #5:
score: 0
Accepted
time: 216ms
memory: 132524kb
input:
2 1
output:
1
result:
ok "1"
Test #6:
score: 0
Accepted
time: 207ms
memory: 132584kb
input:
2 2
output:
2
result:
ok "2"
Test #7:
score: 0
Accepted
time: 215ms
memory: 132436kb
input:
2 3
output:
2
result:
ok "2"
Test #8:
score: 0
Accepted
time: 206ms
memory: 132440kb
input:
2 4
output:
2
result:
ok "2"
Test #9:
score: 0
Accepted
time: 191ms
memory: 132524kb
input:
3 1
output:
1
result:
ok "1"
Test #10:
score: 0
Accepted
time: 187ms
memory: 132528kb
input:
3 2
output:
4
result:
ok "4"
Test #11:
score: 0
Accepted
time: 198ms
memory: 132484kb
input:
3 3
output:
6
result:
ok "6"
Test #12:
score: 0
Accepted
time: 206ms
memory: 132464kb
input:
3 4
output:
6
result:
ok "6"
Test #13:
score: 0
Accepted
time: 215ms
memory: 132512kb
input:
4 1
output:
1
result:
ok "1"
Test #14:
score: 0
Accepted
time: 216ms
memory: 132532kb
input:
4 2
output:
10
result:
ok "10"
Test #15:
score: 0
Accepted
time: 195ms
memory: 132456kb
input:
4 3
output:
18
result:
ok "18"
Test #16:
score: 0
Accepted
time: 198ms
memory: 132528kb
input:
4 4
output:
24
result:
ok "24"
Test #17:
score: 0
Accepted
time: 206ms
memory: 132524kb
input:
99 50
output:
955866606
result:
ok "955866606"
Test #18:
score: 0
Accepted
time: 210ms
memory: 132464kb
input:
99 70
output:
296999003
result:
ok "296999003"
Test #19:
score: 0
Accepted
time: 207ms
memory: 132508kb
input:
1034 998
output:
637688669
result:
ok "637688669"
Test #20:
score: 0
Accepted
time: 215ms
memory: 132496kb
input:
1099 997
output:
712935289
result:
ok "712935289"
Test #21:
score: 0
Accepted
time: 221ms
memory: 132468kb
input:
10314 998
output:
224695890
result:
ok "224695890"
Test #22:
score: 0
Accepted
time: 196ms
memory: 132532kb
input:
10929 9974
output:
160291286
result:
ok "160291286"
Test #23:
score: 0
Accepted
time: 200ms
memory: 132520kb
input:
103124 99448
output:
695932649
result:
ok "695932649"
Test #24:
score: 0
Accepted
time: 206ms
memory: 132532kb
input:
109139 9937
output:
268916696
result:
ok "268916696"
Test #25:
score: 0
Accepted
time: 196ms
memory: 132440kb
input:
1031234 99238
output:
441457721
result:
ok "441457721"
Test #26:
score: 0
Accepted
time: 219ms
memory: 132480kb
input:
1091239 991237
output:
61047495
result:
ok "61047495"
Test #27:
score: 0
Accepted
time: 209ms
memory: 132456kb
input:
10000000 9982443
output:
224744113
result:
ok "224744113"
Test #28:
score: 0
Accepted
time: 201ms
memory: 132500kb
input:
9999977 5678901
output:
641748125
result:
ok "641748125"
Extra Test:
score: 0
Extra Test Passed