QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#112642 | #4471. 随机立方体 | Ignotus | 80 | 1062ms | 234940kb | C++17 | 1.4kb | 2023-06-12 17:32:42 | 2023-06-12 17:32:46 |
Judging History
answer
#include <bits/stdc++.h>
using ll = long long;
const int N = 5e6 + 10;
const ll mod = 998244353;
int T, n, m, l, k;
ll fac[N], inv[N];
ll qpow(ll a, ll b, ll ret = 1){
for( ; b; b >>= 1, a = a * a % mod) if(b & 1) ret = ret * a % mod;
return ret;
}
void init(){
fac[0] = 1;
for(int i = 1; i < N; ++i) fac[i] = fac[i - 1] * i % mod;
inv[N - 1] = qpow(fac[N - 1], mod - 2);
for(int i = N - 2; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % mod;
}
ll binom(int n, int m){
if(n < m || n < 0 || m < 0) return 0;
return fac[n] * inv[m] % mod * inv[n - m] % mod;
}
ll dn(int n, int k){
return fac[n] * inv[n - k] % mod;
}
ll val[N], prod[N], iprod[N], f[N];
void solve(){
std::cin >> n >> m >> l >> k;
int lim = std::min({n, m, l});
for(int i = 1; i <= lim; ++i) val[i] = (1ll * n * m * l - 1ll * (n - i) * (m - i) * (l - i)) % mod;
prod[0] = 1;
for(int i = 1; i <= lim; ++i) prod[i] = val[i] * prod[i - 1] % mod;
iprod[lim] = qpow(prod[lim], mod - 2);
for(int i = lim - 1; i >= 0; --i) iprod[i] = iprod[i + 1] * val[i + 1] % mod;
for(int i = k; i <= lim; ++i) f[i] = dn(n, i) * dn(m, i) % mod * dn(l, i) % mod * iprod[i] % mod;
ll ans = 0;
for(int i = k; i <= lim; ++i){
if((i - k) & 1) ans = (ans - binom(i, k) * f[i] % mod + mod) % mod;
else ans = (ans + binom(i, k) * f[i]) % mod;
}
std::cout << ans << '\n';
}
int main(){
std::cin >> T;
init();
while(T--) solve();
return 0;
}
详细
Test #1:
score: 10
Accepted
time: 27ms
memory: 81668kb
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: 51ms
memory: 81504kb
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: 65ms
memory: 81480kb
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: 48ms
memory: 81492kb
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: 43ms
memory: 81524kb
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: 62ms
memory: 84612kb
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: 170ms
memory: 110560kb
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: 195ms
memory: 112204kb
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: 0
Wrong Answer
time: 945ms
memory: 232780kb
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:
402578116 889382698 72644986 973064240 812669784 686260469 759277220 200811445 409426262 -355911818
result:
wrong answer 1st numbers differ - expected: '723910072', found: '402578116'
Test #10:
score: 0
Wrong Answer
time: 1062ms
memory: 234940kb
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:
686893247 -425522421 391665608 349711190 -312233947 124961208 -621923555 951394533 0 15955223
result:
wrong answer 1st numbers differ - expected: '239923778', found: '686893247'