QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#664669#9254. Random VariablesChenJiarun12345WA 1ms7800kbC++141.5kb2024-10-21 21:40:012024-10-21 21:40:04

Judging History

This is the latest submission verdict.

  • [2024-10-21 21:40:04]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 7800kb
  • [2024-10-21 21:40:01]
  • Submitted

answer

/*
*/
#include <bits/stdc++.h>
using namespace std;
// #define int long long
// #define inf 0x3f3f3f3f3f3f3f3fll
#define For(i,l,r) for(register int i=(l);i<=(r);i++)
#define Rof(i,l,r) for(register int i=(l);i>=(r);i--)
#define bug cout<<"Ln:"<<__LINE__<<'\n'
bool M_S;

const int N=2005;
int n,m,mod,bin[N][N],g[N],f[N][N];
void add(int &x,int y){if((x+=y)>=mod) x-=mod;}
void del(int &x,int y){if((x-=y)<0) x+=mod;}
int qpow(int A,int B){
	int C=1;while(B){
		if(B&1) C=C*A%mod;
		A=A*A%mod,B>>=1;
	}return C;
}
void MAIN(int TEST){
	cin>>n>>m;
	For(i,0,n){
		bin[i][0]=1;
		For(j,1,i) bin[i][j]=(bin[i-1][j-1]+bin[i-1][j])%mod;
	}
	For(k,1,n){
		f[0][0]=1;
		For(i,1,n){
			For(j,0,min(m,i/(k+1))){
				f[i][j]=0;
				if(j<=min(m,(i-1)/(k+1))) add(f[i][j],1ll*f[i-1][j]*(m-j)%mod);
				if(j) add(f[i][j],1ll*f[i-k-1][j-1]%mod*bin[n-i+k][k]%mod*(m-j+1)%mod);
				// 连续考虑k+1个 开头固定在第一个没有填的位置
			}
		}
		For(j,0,min(m,n/(k+1))){
			if(j&1) del(g[k],f[n][j]);
			else add(g[k],f[n][j]);
		}
	}
	int ans=0;
	For(k,1,n) add(ans,1ll*(g[k]-g[k-1]+mod)%mod*k%mod);
	cout<<ans<<'\n';
}

bool M_T;
signed main(){
	// freopen(".in","r",stdin);
	// freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	double T_S=clock();
	// cerr<<"Memory: "<<1.0*(&M_S-&M_T)/1048576<<"MiB\n";

	int test=1;
	cin>>test>>mod;
	For(TEST,1,test) MAIN(TEST);
	
	double T_T=clock();
	// cerr<<"Time: "<<1.0*(T_T-T_S)/CLOCKS_PER_SEC<<"ms\n";
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7800kb

input:

3 123456789
3 2
5 5
7 7

output:

18
7131
2054704

result:

wrong answer 2nd lines differ - expected: '7145', found: '7131'