QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#440605 | #4471. 随机立方体 | james1BadCreeper | 100 ✓ | 936ms | 81356kb | C++17 | 1.6kb | 2024-06-13 21:09:54 | 2024-06-13 21:09:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int P = 998244353;
const int N = 5e6 + 5;
inline int poww(int a, int b) {
if (a == -1) return b % 2 == 0 ? 1 : -1;
int r = 1;
for (; b; b >>= 1, a = 1ll * a * a % P) if (b & 1) r = 1ll * r * a % P;
return r;
}
int fac[N], ifac[N], inv[N], g[N];
inline void initFac(void) {
for (int i = fac[0] = 1; i < N; ++i) fac[i] = 1ll * fac[i - 1] * i % P;
ifac[N - 1] = poww(fac[N - 1], P - 2);
for (int i = N - 2; i >= 0; --i) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % P;
inv[1] = 1;
for (int i = 2; i < N; ++i) inv[i] = 1ll * (P - P / i) * inv[P % i] % P;
}
inline int C(int n, int m) {
return 1ll * fac[n] * ifac[m] % P * ifac[n - m] % P;
}
inline int down(int n, int m) {
return 1ll * fac[n] * ifac[n - m] % P;
}
int main(void) {
initFac();
ios::sync_with_stdio(0); cin.tie(0);
int T; cin >> T;
while (T--) {
int n, m, l, k; cin >> n >> m >> l >> k;
int s = min({n, m, l});
int ans = 0;
int pai = 1;
for (int i = 1; i <= s; ++i)
pai = 1ll * pai * (1ll * n * m % P * l % P - 1ll * (n - i) * (m - i) % P * (l - i) % P) % P;
g[s] = poww(pai, P - 2);
for (int i = s - 1; i >= 1; --i)
g[i] = 1ll * g[i + 1] * (1ll * n * m % P * l % P - 1ll * (n - i - 1) * (m - i - 1) % P * (l - i - 1) % P) % P;
for (int i = k; i <= s; ++i)
ans = (ans + 1ll * poww(-1, i - k) * C(i, k) % P * down(n, i) % P * down(m, i) % P * down(l, i) % P * g[i]) % P;
cout << (ans + P) % P << "\n";
}
return 0;
}
詳細信息
Test #1:
score: 10
Accepted
time: 75ms
memory: 62144kb
input:
9 1 2 2 1 2 1 2 1 2 2 2 1 2 2 1 1 1 2 3 1 2 2 3 1 1 1 3 1 1 2 1 1 2 2 3 1
output:
1 1 142606337 1 1 399297742 1 1 399297742
result:
ok 9 numbers
Test #2:
score: 10
Accepted
time: 62ms
memory: 62236kb
input:
10 11 12 11 1 12 12 10 1 10 12 12 1 12 8 4 1 12 7 10 1 10 12 12 1 12 11 12 1 12 12 10 1 12 8 5 1 11 12 10 1
output:
964117340 313668413 313668413 391814806 769515445 313668413 409827311 313668413 276258321 547984948
result:
ok 10 numbers
Test #3:
score: 10
Accepted
time: 74ms
memory: 62216kb
input:
10 12 11 11 11 12 12 2 2 12 11 8 5 12 10 10 9 9 12 9 4 11 12 12 6 12 4 12 5 11 12 10 3 10 11 11 3 11 12 12 8
output:
668009782 890649154 271209916 937875427 630982635 140920141 0 437327840 742478817 773295187
result:
ok 10 numbers
Test #4:
score: 10
Accepted
time: 75ms
memory: 62300kb
input:
10 100 66 92 57 97 100 77 3 100 92 95 69 86 98 97 30 91 94 98 85 35 95 54 96 91 20 93 2 71 100 81 65 93 96 100 3 100 100 68 20
output:
314376207 763625649 23307893 827148291 280829208 0 122744808 628776470 314819928 823785335
result:
ok 10 numbers
Test #5:
score: 10
Accepted
time: 82ms
memory: 62216kb
input:
10 992 924 949 1 991 507 917 1 992 595 701 1 937 992 967 1 983 960 905 1 992 932 996 1 995 971 645 1 917 992 996 1 994 993 996 1 15 1000 1000 1
output:
229417522 351302489 629390104 246106927 862307736 844052618 66055569 913422543 337236312 278988015
result:
ok 10 numbers
Test #6:
score: 10
Accepted
time: 98ms
memory: 62560kb
input:
10 94710 91605 99101 55 18512 79378 99834 1 99658 97773 92656 31 99155 99139 99698 44 99747 94914 99742 49 97452 99398 96607 87 86012 76191 75937 42 99217 98167 99164 32 98058 87372 57032 73 92807 73444 99668 15
output:
11312811 294655439 70723955 151174517 538799105 344255344 899533255 429432051 2152996 431450316
result:
ok 10 numbers
Test #7:
score: 10
Accepted
time: 205ms
memory: 65884kb
input:
10 520078 928588 676646 1 992873 719234 702486 1 996614 861181 152528 1 996654 927109 996108 1 830126 218745 922743 1 587118 796679 905415 1 922146 969275 731212 1 970141 851397 997226 1 923346 780416 990579 1 944434 929901 992364 1
output:
638628415 78605624 973978919 300798323 441618627 565785141 918707550 591320093 313210070 0
result:
ok 10 numbers
Test #8:
score: 10
Accepted
time: 188ms
memory: 66052kb
input:
10 995437 970803 346183 19 991927 994256 906723 21 992315 648327 901145 70 924884 978458 948349 48 955785 951761 326193 50 860923 165778 939919 53 991512 983509 983023 55 990758 995005 714970 14 996251 621454 992477 78 990147 880093 908839 70
output:
168170437 674625485 575021422 657991968 539858782 978379982 512209101 317609800 271534305 442516894
result:
ok 10 numbers
Test #9:
score: 10
Accepted
time: 832ms
memory: 81060kb
input:
10 4812995 4597958 4997619 1 4698223 4927285 4716397 1 3888126 4497028 4513559 1 4953155 4982658 4622527 1 3990178 4958258 2671458 1 357883 4956337 3719989 1 4923080 4997234 4841397 1 4980872 4973577 4695751 1 4670227 4530539 4986963 1 4851624 4632350 4558600 1
output:
723910072 849159504 341235107 503935908 616030546 686260469 205958291 476672538 598436093 346856672
result:
ok 10 numbers
Test #10:
score: 10
Accepted
time: 936ms
memory: 81356kb
input:
10 4973645 4986915 4849600 96 4951053 4740469 3999936 56 4719113 4869923 4985155 72 4973301 4708629 4982742 92 4743191 4885631 4953269 85 4530720 4959089 4976548 17 4975615 4910052 4988683 69 4980376 4971246 3830334 75 4699883 4988989 4191443 82 4553734 4965926 4962568 75
output:
239923778 769296696 92076376 412346289 771403526 683282238 697454766 396743794 967155247 990632942
result:
ok 10 numbers
Extra Test:
score: 0
Extra Test Passed