ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213023 | #3823. 艾特扣德 | 13270460609 | 100 | 778ms | 18084kb | C++ | 1.1kb | 2024-11-03 09:15:39 | 2024-11-03 13:01:42 |
answer
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 1e6;
const int maxn = 1e6 + 5;
const long long mod = 998244353;
long long fpm(long long x, long long y) {
long long res = 1ll;
if (y < 0) y += mod - 1;
for (; y; y >>= 1, x = x * x % mod)
if (y & 1) res = res * x % mod;
return res;
}
long long fac[maxn], inv[maxn];
long long C(int n, int m) {
if (n < m) return 0ll;
return fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int T, n, m;
int a[maxn];
int main() {
fac[0] = 1;
for (int i = 1; i <= N; i++) fac[i] = fac[i - 1] * (long long)i % mod;
inv[N] = fpm(fac[N], -1);
for (int i = N; i >= 1; i--) inv[i - 1] = inv[i] * (long long)i % mod;
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &m);
int mn = N;
for (int i = 1; i <= m; mn = min(mn, a[i++])) scanf("%d", a + i);
int cnt = n - m - (mn ? (mn - 1) : 0);
long long ans = (mn ? ((long long)(m + 1) * fac[mn] % mod) : 1ll) * fac[n] % mod * inv[m + mn] % mod;
printf("%lld\n", ans);
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 20
Accepted
time: 13ms
memory: 16824kb
input:
100 4 4 3 0 1 2 3 1 0 5 2 1 3 5 3 1 4 2 5 3 0 4 2 3 1 0 5 1 3 3 3 1 2 0 3 1 0 4 3 0 2 3 4 2 0 2 5 1 ...
output:
1 6 60 20 20 6 60 1 6 4 12 60 1 20 24 4 4 12 1 1 12 24 4 1 3 60 20 18 8 1 2 2 1 120 1 60 20 12 5 60 ...
result:
ok 100 lines
Test #2:
score: 20
Accepted
time: 430ms
memory: 16824kb
input:
1000000 420929 1 239064 93187 1 85123 171379 1 110159 658643 1 0 303046 1 95912 800861 1 781035 9893...
output:
598226497 5378332 940486345 191686493 851534199 252669865 212185508 798010858 291752994 157602834 48...
result:
ok 1000000 lines
Test #3:
score: 20
Accepted
time: 111ms
memory: 18084kb
input:
38765 832568 1 0 992725 6 548209 466528 628957 748938 0 578853 943934 15 863133 363066 513728 634152...
output:
485766967 626192578 109003053 452562070 536252017 398732909 215760199 971680463 57876225 982883068 7...
result:
ok 38765 lines
Test #4:
score: 20
Accepted
time: 109ms
memory: 18064kb
input:
38573 988634 10 800634 876452 811249 495916 842656 695203 0 914758 757887 237251 948749 6 282623 267...
output:
184333188 275156102 888302414 617843139 541399598 910523975 537526380 145847577 319719384 409299415 ...
result:
ok 38573 lines
Test #5:
score: 20
Accepted
time: 115ms
memory: 17908kb
input:
38561 996249 6 150367 424546 851150 536915 420708 392670 956743 7 858128 296060 304111 814957 936254...
output:
204801326 604783715 806845893 211130612 389598777 860376551 982837756 742666989 686982798 978300064 ...
result:
ok 38561 lines
Extra Test:
score: 0
Extra Test Passed