QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#88410 | #5826. 错排 | ooooxxxx | 20 | 1422ms | 628856kb | C++14 | 1.7kb | 2023-03-16 10:26:19 | 2023-03-28 12:27:03 |
Judging History
answer
#include<iostream>
#include<cstring>
using namespace std;
const int mod=998244353;
const int N=2e5+1000,M=2e5+100,B=510;
#define int long long
int f[N],finv[N];
inline int qpow(int a,int b){
int ret=1;
while(b){
if(b&1) ret=ret*a%mod;
a=a*a%mod;b>>=1;
}return ret;
}
inline int comb(int n,int m){
if(n<m||m<0) return 0;
return f[n]*finv[m]%mod*finv[n-m]%mod;
}
int n,m;
int g[510][N],inv[N];
inline void init(){
for(int m=0;m<=M;m+=B){
int i=m/B;
g[i][0]=1;
g[i][1]=(m-1)*g[i][0]%mod;
for(int n=2;n<=M;n++){
g[i][n]=inv[n]*(g[i][n-1]*(n+m-2)%mod+g[i][n-2])%mod;
}
}
}
// inline int DP(int n,int m){
// if(n-2*m<0) return 0;
// return (f[n-m]*f[m]%mod*dp[m+1][n-2*m]%mod+mod)%mod;
// }
int s[4];
inline int pval(int x,int y){
if(x<0) return 0;
if(x%B==0)return g[x/B][y];
int pre=x/B+1;
s[0]=g[pre][y],s[1]=g[pre][y+1],s[2]=g[pre][y+2];
int n=y+2;
for(int m=pre*B-1;m>=x;m--){
s[2]=(s[2]-s[1])%mod;
s[1]=(s[1]-s[0])%mod;
s[0]=(n*s[2]-(n+m-2)*s[1])%mod;
}
return s[0];
}
int x,y;
inline void solve(){
cin>>n>>m;
int prod=f[n-m]*f[m]%mod;
x=m+1,y=n-2*m;
cout<<(prod*pval(x,y)%mod+mod)%mod<<'\n';
}
int32_t main(){
// freopen("qwq.in","r",stdin);freopen("qwq.out","w",stdout);
f[0]=finv[0]=1;
for(int i=1;i<=M;i++) f[i]=f[i-1]*i%mod;
finv[M]=qpow(f[M],mod-2);
for(int i=M-1;i>=1;i--) finv[i]=finv[i+1]*(i+1)%mod;
for(int i=1;i<=M;i++) inv[i]=f[i-1]*finv[i]%mod;
inv[M+1]=qpow(M+1,mod-2);
cerr<<"???"<<endl;
init();
int T;ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
cin>>T;
while(T--) solve();
}
详细
Subtask #1:
score: 1
Accepted
Test #1:
score: 1
Accepted
time: 645ms
memory: 628740kb
input:
0
output:
result:
ok 0 number(s): ""
Subtask #2:
score: 9
Accepted
Test #2:
score: 9
Accepted
time: 617ms
memory: 626868kb
input:
10 8 6 5 1 4 2 6 3 8 1 3 1 6 2 3 1 4 1 6 2
output:
0 44 4 36 14833 2 168 2 9 168
result:
ok 10 numbers
Test #3:
score: 0
Accepted
time: 657ms
memory: 626700kb
input:
10 8 1 8 4 6 3 8 2 8 3 6 3 6 1 7 3 2 1 8 3
output:
14833 576 36 10860 4680 36 265 432 1 4680
result:
ok 10 numbers
Test #4:
score: 0
Accepted
time: 637ms
memory: 626744kb
input:
10 7 5 3 1 8 3 7 3 8 1 4 1 5 2 6 3 7 1 7 3
output:
0 2 4680 432 14833 9 24 36 1854 432
result:
ok 10 numbers
Test #5:
score: 0
Accepted
time: 636ms
memory: 626636kb
input:
10 7 2 8 4 6 1 5 1 8 2 6 3 4 2 8 3 3 1 8 1
output:
1280 576 265 44 10860 36 4 4680 2 14833
result:
ok 10 numbers
Test #6:
score: 0
Accepted
time: 637ms
memory: 626796kb
input:
10 6 6 3 1 8 3 2 1 7 1 3 1 6 2 8 4 7 3 7 0
output:
0 2 4680 1 1854 2 168 576 432 1854
result:
ok 10 numbers
Subtask #3:
score: 10
Accepted
Test #7:
score: 10
Accepted
time: 1422ms
memory: 626820kb
input:
200000 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 12 0 13 0 14 0 15 0 16 0 17 0 18 0 19 0 20 0 21 0 22 0 23 0 24 0 25 0 26 0 27 0 28 0 29 0 30 0 31 0 32 0 33 0 34 0 35 0 36 0 37 0 38 0 39 0 40 0 41 0 42 0 43 0 44 0 45 0 46 0 47 0 48 0 49 0 50 0 51 0 52 0 53 0 54 0 55 0 56 0 57 0 58 0 59 0 60 0 61...
output:
0 1 2 9 44 265 1854 14833 133496 1334961 14684570 176214841 294304226 127281753 910981941 600290115 222488424 11814221 224470198 496426549 442513998 751108780 305347938 340640042 530046225 804025262 745550660 910531421 451058030 554564312 221339670 95158970 145512950 954462889 464137465 737039093 31...
result:
ok 200000 numbers
Subtask #4:
score: 0
Wrong Answer
Test #8:
score: 20
Accepted
time: 1094ms
memory: 628792kb
input:
200000 4303 1473 1276 72 967 234 3619 984 1316 384 2679 50 4426 1744 3782 1179 4919 4 805 63 3933 158 1574 528 1277 435 3826 915 2739 68 2286 349 3017 527 3036 476 4280 1764 1504 686 4584 917 1379 145 4764 2178 1881 45 4808 1565 3663 165 4730 2209 2258 103 4181 1687 1636 770 4339 1173 2355 777 3201 ...
output:
855518783 202627962 284771116 596280162 111952425 28114068 922980998 483503998 478475869 42227903 210453242 82826277 349706660 478397018 588903665 672339856 911511930 783922264 224272260 199537336 659467844 383745708 953695418 668329703 880293299 649430530 916687905 550953325 295023552 141584429 871...
result:
ok 200000 numbers
Test #9:
score: 0
Accepted
time: 1083ms
memory: 626680kb
input:
200000 4558 644 2015 866 4752 1612 4343 704 4455 1277 4761 1069 1173 434 2150 1002 3226 132 4556 1468 4362 2008 3194 936 4750 1712 4133 58 4670 2111 3787 1705 1006 458 4973 1489 2520 934 3971 1256 4130 522 1648 28 4843 1800 3535 1031 2363 345 2722 1187 4620 1677 3738 325 3783 447 2026 617 4992 1595 ...
output:
878092359 137664342 571257477 157127504 385052631 35779181 650061801 617898174 375209372 721222702 707783783 410748088 991469920 69775359 76681433 134815341 199607624 126498594 149881281 563970794 786560573 94902562 668383803 802669973 229778708 749799553 295203934 163664840 140841030 547218181 2572...
result:
ok 200000 numbers
Test #10:
score: -20
Wrong Answer
time: 1072ms
memory: 626824kb
input:
200000 4763 4669 4281 319 1441 342 1078 224 2092 1022 1666 78 2623 660 4797 1258 4878 1616 3255 931 619 85 3632 220 3163 1358 4177 1838 3072 746 938 59 4038 1283 3825 618 4889 1090 3988 1380 686 237 4488 139 3189 572 4790 263 2862 340 3325 261 2351 1141 3047 659 2562 445 4947 1894 2504 717 3399 1176...
output:
469836907 283193141 728175842 611328334 18202018 506844457 979367956 585351167 337548843 72363572 243634086 313739474 707317304 637199005 278105669 961177961 957750794 767835509 349772711 198594249 245831996 37104891 398916514 263271106 843118755 308147020 690301962 174120745 179202564 216399429 946...
result:
wrong answer 1st numbers differ - expected: '0', found: '469836907'
Subtask #5:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #13:
score: 20
Accepted
time: 633ms
memory: 628856kb
input:
10 94764 1149 111140 21372 59140 20928 73376 27175 59837 4344 160865 25705 44518 10326 145794 64106 147628 12887 103719 39458
output:
139176963 393241499 258873190 39229362 870875380 975228452 243360193 751148936 95574458 297629235
result:
ok 10 numbers
Test #14:
score: -20
Wrong Answer
time: 642ms
memory: 628748kb
input:
10 158002 80444 9451 2903 173427 12416 137154 16538 166581 24311 127365 41216 190696 67064 103832 40293 108767 52320 109966 50541
output:
14329289 702735124 750025710 841222658 375040035 583566228 649803213 746573713 113561055 257165994
result:
wrong answer 1st numbers differ - expected: '0', found: '14329289'
Subtask #6:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
0%