QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#728449 | #9572. Bingo | ucup-team5319# | AC ✓ | 131ms | 29556kb | C++14 | 5.2kb | 2024-11-09 15:12:08 | 2024-11-09 15:12:10 |
Judging History
answer
//Linkwish's code
#include<bits/stdc++.h>
#define endl '\n'
#define si inline
#define fi first
#define se second
using namespace std;
typedef long long ll;typedef __int128 li;typedef long double ld;
typedef pair<int,int> pii;typedef pair<ll,ll> pll;
typedef const int ci;typedef const ll cl;ci iinf=1e9;cl linf=LLONG_MAX;
template<typename T>si bool gmax(T &x,const T y){if(x<y)return x=y,1;return 0;}
template<typename T>si bool gmin(T &x,const T y){if(y<x)return x=y,1;return 0;}
namespace LinkWish{
ci N=(1<<19),M=N,mod=998244353;
si int qpow(int x,int y){
int res=1;
for(;y;x=1ll*x*x%mod,y>>=1)if(y&1)res=1ll*res*x%mod;
return res;
}
si int GMod(ci x){return x>mod?x-mod:x;}
int lena=N,lenb=N;
int A[M],B[M];
int lg,lim,P[M];
si void calclim(){lim=1<<(lg=__lg(lena+lenb)+1);}
si void Init(){
calclim();
for(int i=0,j=1,w;i<lg;i++){
w=qpow(3,(mod-1)>>(i+1)),P[j++]=1;
for(;j<(2<<i);j++)P[j]=1ll*P[j-1]*w%mod;
}
}
si void DIF(int *a){
for(int i=lg-1,len=lim>>1;~i;i--,len>>=1){
for(int j=0;j<lim;j+=(len<<1)){
for(int k=j,x,y,cur=len;k<j+len;k++,cur++){
x=a[k],y=a[k+len];
a[k]=GMod(x+y),a[k+len]=1ll*(x-y+mod)*P[cur]%mod;
}
}
}
}
si void DIT(int *a){
for(int i=0,len=1;i<lg;i++,len<<=1){
for(int j=0;j<lim;j+=(len<<1)){
for(int k=j,x,y,cur=len;k<j+len;k++,cur++){
x=a[k],y=1ll*a[k+len]*P[cur]%mod;
a[k]=GMod(x+y),a[k+len]=GMod(x-y+mod);
}
}
}
reverse(a+1,a+lim);
for(int i=0,inv=qpow(lim,mod-2);i<lim;i++)a[i]=1ll*a[i]*inv%mod;
}
int n=400003;
vector<int> e[N];
int fac[N],inv[N];
si void init(){
fac[0]=1;for(int i=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%mod;
inv[n]=qpow(fac[n],mod-2);for(int i=n-1;~i;i--)inv[i]=1ll*inv[i+1]*(i+1)%mod;
}
si int C(int x,int y){
if(x<0||y<0||x<y)return 0;
return 1ll*fac[x]*inv[y]%mod*inv[x-y]%mod;
}
int sz[N],cnt[N];
void dfs(int x,int fa){
sz[x]=1;
for(int to:e[x])if(to!=fa)dfs(to,x),sz[x]+=sz[to];
cnt[sz[x]]++,cnt[n-sz[x]]++;
}
void mian(){
init();
int t; scanf("%d", &t); while (t--) {
int n, m; scanf("%d %d", &n, &m);
lena=n*m, lenb = n*m, Init();
// for(int i=0;i<=n;i++){
// A[i]=inv[i];
// B[i]=1ll*cnt[n-i+1]*fac[n-i+1]%mod;
// }
static int w[200005], a[200005];
for (int i = 0; i <= n * m; i++) w[i] = 0;
for (int i = 1; i <= n * m; i++) scanf("%d", &a[i]);
sort(a + 1, a + 1 + n * m);
for (int i = 0; i <= n; i++) for (int j = 0; j <= m; j++) {
if (i == n && j == m) continue;
if ((n + m - i - j) & 1) w[i * j] = (w[i * j] + 1ll * fac[n] * inv[i] % mod * inv[n - i] % mod * fac[m] % mod * inv[j] % mod * inv[m - j]) % mod;
else w[i * j] = (w[i * j] + 1ll * (mod - fac[n]) * inv[i] % mod * inv[n - i] % mod * fac[m] % mod * inv[j] % mod * inv[m - j]) % mod;
}
for (int i = 0; i < lim; i++) A[i] = 0, B[i] = 0;
for (int i = 0; i <= n * m; i++) A[i] = 1ll * w[i] * fac[i] % mod;
for (int i = 0; i <= n * m; i++) B[i] = inv[i];
reverse(B, B + n * m + 1);
// for (int i = 0; i <= n * m; i++) printf("%d%c", w[i], " \n"[i == n * m]);
// A[0] = 0; for (int i = 1; i <= n; i++) A[i] = 1ll * inv[i - 1] * inv[i - 1] % mod;
// B[0] = 0; for (int i = 1; i < m; i++) B[i] = 1ll * inv[i - 1] * inv[i - 1] % mod;
DIF(A),DIF(B);
for(int i=0;i<lim;i++)A[i]=1ll*A[i]*B[i]%mod;
DIT(A);
for (int i = 0; i <= n*m; i++) w[i] = 1ll * A[i + n * m] * inv[i] % mod;
for (int i = 0; i <= n*m; i++) w[i] = 1ll * w[i] * fac[i] % mod * fac[n*m - i] % mod;
// for (int i = 0; i <= n * m; i++) printf("%d%c", w[i], " \n"[i == n * m]);
for (int i = 0; i < n * m; i++) w[i] = (w[i] + mod - w[i + 1]) % mod;
int ans = 0;
for (int i = 0; i < n * m; i++) ans = (ans + 1ll * w[i] * a[n * m- i]) % mod;
printf("%d\n", ans);
// memset(A, 0, sizeof A); memset(B, 0, sizeof B);
// A[0] = 0; for (int i = 1; i <= n; i++) A[i] = 1ll * inv[i] * (i == 1 ? 0 : inv[i - 2]) % mod;
// B[0] = 0; for (int i = 1; i < m; i++) B[i] = 1ll * inv[i] * (i == 1 ? 0 : inv[i - 2]) % mod;
// // for (int i = 1; i <= n; i++) printf("@ %d\n", A[i]);
// // for (int i = 1; i < m; i++) printf("# %d\n", B[i]);
// DIF(A),DIF(B);
// for(int i=0;i<lim;i++)A[i]=1ll*A[i]*B[i]%mod;
// DIT(A);
// // for (int i = 2; i < n + m; i++) printf("! %d %lld\n", A[i], 1ll * fac[i - 2] * fac[i - 2] % mod * A[i] % mod);
// for (int i = 2; i < n + m; i++) ans = (ans + 1ll * (mod - fac[i - 2]) * fac[i - 2] % mod * A[i]) % mod;
// printf("%d\n", (ans + 2) % mod);
}
}
}
signed main(){
// #ifndef ONLINE_JUDGE
// assert(freopen("in.in","r",stdin));
// #endif
// ios::sync_with_stdio(0);
// cin.tie(0),cout.tie(0);
LinkWish::mian();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 28468kb
input:
4 2 2 1 3 2 4 3 1 10 10 10 1 3 20 10 30 3 4 1 1 4 5 1 4 1 9 1 9 8 10
output:
56 60 60 855346687
result:
ok 4 number(s): "56 60 60 855346687"
Test #2:
score: 0
Accepted
time: 6ms
memory: 28344kb
input:
1 2 2 0 0 998244352 998244352
output:
998244345
result:
ok 1 number(s): "998244345"
Test #3:
score: 0
Accepted
time: 57ms
memory: 28520kb
input:
900 1 1 810487041 1 2 569006976 247513378 1 3 424212910 256484544 661426830 1 4 701056586 563296095 702740883 723333858 1 5 725786515 738465053 821758167 170452477 34260723 1 6 204184507 619884535 208921865 898995024 768400582 369477346 1 7 225635227 321139203 724076812 439129905 405005469 369864252...
output:
810487041 495026756 540662911 541929691 118309348 270925149 575366228 709974238 761347712 304011276 14811741 366145628 638305530 240546928 484276475 603344008 926633861 161768904 239961447 329781933 315752584 578075668 259941994 600147169 402221164 890998500 154285994 181862417 47930994 273729619 64...
result:
ok 900 numbers
Test #4:
score: 0
Accepted
time: 75ms
memory: 26380kb
input:
400 1 995 548100968 635656907 177366910 971271357 314579375 529572241 948721678 455918644 95745688 164857981 499083775 827896554 496889261 111294651 646048809 758286431 163045934 917399362 189372614 267754648 966443706 921589740 228089960 473153545 482816423 37567957 495730380 864445591 568695110 78...
output:
954668084 677509135 636173666 415373646 477286237 209886549 398423120 24466622 672440292 390142124 498517438 305197486 239833057 500821845 475519894 347179487 974036742 810602822 75196204 48378743 393961176 290898056 957916898 434124418 663457674 225283495 704304053 338701802 670053839 137083082 165...
result:
ok 400 numbers
Test #5:
score: 0
Accepted
time: 102ms
memory: 26440kb
input:
40 92 99 14480275 12892621 932457558 584861415 926346518 101583802 498448003 884757899 463949215 661256632 872663851 651132350 565253214 18404795 810166895 145370572 123351313 298382303 777283720 775900024 613503856 817112784 713304484 541301622 595768594 550989875 960159831 571815058 777864097 3608...
output:
614712898 16225927 313765200 824491114 60971514 769510634 58341639 808667102 527187053 319496150 267177120 409701892 245708713 115397703 928197397 533118123 931076329 448328887 672878477 180728812 385639338 504093069 846218180 981546177 906805965 315620628 863877552 348963788 781585156 982673320 275...
result:
ok 40 numbers
Test #6:
score: 0
Accepted
time: 91ms
memory: 28528kb
input:
40 86 92 479103936 690362573 387313968 428679987 770097821 67859949 744428797 919332570 530162857 389639443 851979342 310332074 863845681 155743453 442066584 996725021 385646576 447381083 64960590 818019444 260564007 16381359 36238584 609449698 12466296 532193395 262308857 279184524 454814687 400578...
output:
147127348 995441625 947321329 200561175 846810174 626764591 235790337 30932003 384829067 254218916 20342301 451884441 634808121 241161955 246093492 515701050 978130791 502129313 3431507 775910032 464454612 153447682 53092548 316439192 101505498 40191013 225025922 133184210 209384134 330521977 360716...
result:
ok 40 numbers
Test #7:
score: 0
Accepted
time: 128ms
memory: 28644kb
input:
2 447 447 790583748 764745604 779691526 67598288 308196334 738524513 685610494 336125979 294155123 651917356 898366384 420012139 529304950 133567869 630219750 62853597 606184670 383809162 43962071 826608376 652871696 860138865 675639996 444122802 823442992 841633845 125418467 211407031 726738308 984...
output:
506347658 891054810
result:
ok 2 number(s): "506347658 891054810"
Test #8:
score: 0
Accepted
time: 120ms
memory: 28684kb
input:
2 100 2000 414412015 610256524 548060717 581032168 761297097 50124687 831351681 906381893 842125801 82512258 734351512 844649420 370666628 791011946 232557748 968208094 238084359 933173727 306257334 509581201 774756848 370039888 322700146 641635730 8423279 909781921 238370638 28574480 725141803 9941...
output:
380238486 147107381
result:
ok 2 number(s): "380238486 147107381"
Test #9:
score: 0
Accepted
time: 128ms
memory: 29280kb
input:
2 2000 100 432504867 225538929 546658423 260257767 682179463 892187612 142884587 872658039 89862243 117086929 104310686 342803717 47992235 148221787 695186286 875318238 264248632 320257869 568552597 54600213 364423602 412159309 666014765 235168890 795627687 977929998 351322809 9778000 723545298 1693...
output:
807761546 460321345
result:
ok 2 number(s): "807761546 460321345"
Test #10:
score: 0
Accepted
time: 124ms
memory: 28212kb
input:
2 10 20000 450597719 675029617 315027614 635737834 439025757 505777670 590615658 142679716 637832921 847916068 472514213 71186529 723562195 273447466 297524284 782428382 428366719 869622434 528857976 735817391 650344824 152288845 779100871 130691934 584587742 513859676 996493379 687235989 189730396 ...
output:
579362183 459093435
result:
ok 2 number(s): "579362183 459093435"
Test #11:
score: 0
Accepted
time: 129ms
memory: 29556kb
input:
2 20000 10 770680455 822530420 615615204 314963433 892126521 815622197 900392916 410945746 187559247 278510970 538727855 101559225 98897919 326911775 760152822 689538526 60266407 256706575 791153240 418790216 772229976 194408266 426161021 328204862 71557913 976272337 111201197 504403438 188133891 58...
output:
30164141 385139412
result:
ok 2 number(s): "30164141 385139412"
Test #12:
score: 0
Accepted
time: 130ms
memory: 28444kb
input:
2 100000 2 224212357 458006968 163025536 269449920 699657932 932776912 420937536 166351734 685658904 344666962 946460500 884461444 228370491 174980092 646368291 854381092 617669653 366836379 717071379 463349902 749408189 163205331 665200568 666647060 230069001 195048922 357469436 37819596 212080713 ...
output:
188269415 372357321
result:
ok 2 number(s): "188269415 372357321"
Test #13:
score: 0
Accepted
time: 121ms
memory: 28988kb
input:
2 2 100000 242305209 73289374 463613125 946919872 154514343 546366969 34460325 132627880 629649815 379241632 14429790 612844256 207685982 530434285 412742360 761491236 249569341 450174989 677376758 146322726 339074943 507314636 10270834 864159988 715283525 729222953 772411491 19023116 374520280 8624...
output:
178386797 319825470
result:
ok 2 number(s): "178386797 319825470"
Test #14:
score: 0
Accepted
time: 131ms
memory: 28192kb
input:
2 1 200000 562387945 522780061 928236786 626145471 377386592 856211496 180201513 702883794 179376140 808080887 382633317 110998553 883255942 655659964 711334827 668601380 413687428 303285085 939672021 525550020 460960094 549434056 957565221 759683032 202253696 797371030 885363662 532445034 674913659...
output:
499141558 710898596
result:
ok 2 number(s): "499141558 710898596"
Extra Test:
score: 0
Extra Test Passed