QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#733939#9572. Bingoucup-team134WA 3ms7820kbC++172.7kb2024-11-10 22:15:332024-11-10 22:15:34

Judging History

你现在查看的是最新测评结果

  • [2024-11-10 22:15:34]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:7820kb
  • [2024-11-10 22:15:33]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=998244353;
int add(int x,int y){x+=y;return x>=mod?x-mod:x;}
int sub(int x,int y){x-=y;return x<0?x+mod:x;}
int mul(int x,int y){return (ll)x*y%mod;}
void ckadd(int &x,int y){x=add(x,y);}
void cksub(int &x,int y){x=sub(x,y);}

const int N=400050;
int F[N],I[N];
int binom(int n,int k){
    return mul(F[n],mul(I[k],I[n-k]));
}
int c[N];
vector<int> vls;
void precalc(int n,int m){
	for(int k=0;k<=n*m;k++)c[k]=0;
	vls.clear();
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
        	int now=mul(binom(n,i),binom(m,j));
        	int sm=(n-i)*(m-j);
        	if((i+j)%2==0)ckadd(c[sm],now);
        	else cksub(c[sm],now);
        }
    }
	for(int k=0;k<=n*m;k++)if(c[k]!=0)vls.push_back(k);
}
int SolveInclusionExclusion(int cnt){
	int ans=0;
	for(int j=(int)vls.size()-1;j>=0;j--){
		int sm=vls[j];
		if(sm<cnt)break;
		ckadd(ans,mul(binom(sm,cnt),c[sm]));
	}
    return ans;
}

int Solve(int n,int m,int cnt){
    vector<vector<int>> dp(n+1,vector<int>(m+1,0));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(i*j>=cnt){
                dp[i][j]=binom(i*j,cnt);
                for(int a=0;a<=i;a++){
                    for(int b=0;b<=j;b++){
                        if(a==0 && b==0)continue;
                        if(a==i && b!=j)continue;
                        if(b==j && a!=i)continue;
                        cksub(dp[i][j],mul(dp[i-a][j-b],mul(binom(i,a),binom(j,b))));
                    }
                }
            }
        }
    }
    return dp[n][m];
    /*if(cnt>n*m)return 0;
    if(n>m)swap(n,m);
    int ans=binom(n*m,cnt);
    for(int i=1;i<=n;i++){
        int now=mul(Solve(n-i,m,cnt),binom(n,i));
        if(i%2==1)cksub(ans,now);
        else ckadd(ans,now);
    }
    return ans;*/
}

int main(){
    F[0]=1;
    for(int i=1;i<N;i++)F[i]=mul(F[i-1],i);
    I[0]=I[1]=1;
    for(int i=2;i<N;i++)I[i]=mul(mod-mod/i,I[mod%i]);
    for(int i=1;i<N;i++)I[i]=mul(I[i-1],I[i]);
    int t;
    scanf("%i",&t);
    while(t--){
        int n,m;
        scanf("%i %i",&n,&m);
        precalc(n,m);
        vector<int> a(n*m);
        for(int i=0;i<n*m;i++){
            scanf("%i",&a[i]);
        }
        sort(a.begin(),a.end());
        int ans=0;
        for(int i=0;i<n*m;i++){
            int diff=(i==0?a[i]:a[i]-a[i-1]);
            if(diff==0)continue;
            int ways=mul(mul(F[n*m-i],F[i]),SolveInclusionExclusion(n*m-i));
            ckadd(ans,mul(diff,ways));
            printf("bingo>=%i ways=%i\n",a[i],ways);
        }
        printf("%i\n",ans);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 7820kb

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:

bingo>=1 ways=24
bingo>=2 ways=24
bingo>=3 ways=8
bingo>=4 ways=0
56
bingo>=10 ways=6
60
bingo>=10 ways=6
bingo>=20 ways=0
bingo>=30 ways=0
60
bingo>=1 ways=479001600
bingo>=4 ways=377395200
bingo>=5 ways=137894400
bingo>=8 ways=34836480
bingo>=9 ways=0
bingo>=10 ways=0
855346687

result:

wrong output format Expected integer, but "bingo>=1" found