QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#290617 | #4471. 随机立方体 | MoRanSky | 100 ✓ | 1454ms | 81988kb | C++23 | 2.3kb | 2023-12-25 06:08:04 | 2023-12-25 06:08:05 |
Judging History
answer
// Skyqwq
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; }
template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; }
template <typename T> void inline read(T &x) {
int f = 1; x = 0; char s = getchar();
while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
x *= f;
}
const int N = 5e6 + 5, P = 998244353, M = P - 1;
int fact[N], infact[N], pa[N], ia[N];
int inline power(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = (LL)res * a % P;
a = (LL)a * a % P;
b >>= 1;
}
return res;
}
void inline add(int &x, int y) {
x += y;
if (x >= P) x -= P;
}
void inline factPrework(int n) {
fact[0] = infact[0] = 1;
for (int i = 1; i <= n; i++) fact[i] = (LL)fact[i - 1] * i % P;
infact[n] = power(fact[n], P - 2);
for (int i = n - 1; i; i--) infact[i] = infact[i + 1] * (i + 1ll) % P;
}
int inline C(int a, int b) {
if (a < b || a < 0 || b < 0) return 0;
return (LL)fact[a] * infact[b] % P * infact[a - b] % P;
}
int n, m, l, inv2 = (P + 1) / 2;
LL num;
int inline get(int k) {
int v = 1ll * C(n, k) * C(m, k) % P * C(l, k) % P * fact[k] % P * fact[k] % P * fact[k] % P;
v = 1ll * v * ia[k] % P;
return v;
}
int inline g(int i) {
return (1ll * n * m % P * l % P - 1ll * (n - i) * (m - i) % P * (l - i) % P + P) % P;
}
int main() {
factPrework(5e6);
int T; read(T);
while (T--) {
int k; read(n), read(m), read(l), read(k);
int len = min(n, min(m, l));
pa[0] = ia[0] = 1;
for (int i = 1; i <= len; i++)
pa[i] = 1ll * pa[i - 1] * g(i) % P;
ia[len] = power(pa[len], P - 2);
for (int i = len - 1; i; i--)
ia[i] = 1ll * ia[i + 1] * g(i + 1) % P;
int ans = 0;
for (int i = k; i <= len; i++) {
int w = 1ll * get(i) * C(i, k) % P;
if ((i - k) & 1) add(ans, P - w);
else add(ans, w);
}
printf("%d\n", ans);
}
return 0;
}
详细
Test #1:
score: 10
Accepted
time: 40ms
memory: 45440kb
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: 39ms
memory: 45068kb
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: 40ms
memory: 46600kb
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: 44ms
memory: 45500kb
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: 34ms
memory: 46024kb
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: 69ms
memory: 48112kb
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: 239ms
memory: 53196kb
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: 255ms
memory: 55236kb
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: 1270ms
memory: 81988kb
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: 1454ms
memory: 81956kb
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