QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#779653 | #9254. Random Variables | byron10000 | WA | 4ms | 13404kb | C++14 | 1.8kb | 2024-11-24 20:48:47 | 2024-11-24 20:48:49 |
Judging History
answer
#if defined(_USE_PCH_)
#include "pch.hpp"
#else
#include <bits/stdc++.h>
#endif
#define RNG(V_, A_, B_, ...) for(int V_=(A_), V_##_END=(B_) __VA_OPT__(,) __VA_ARGS__; V_<=V_##_END; V_++)
#define IRNG(V_, A_, B_, ...) for(int V_=(A_), V_##_END=(B_) __VA_OPT__(,) __VA_ARGS__; V_>=V_##_END; V_--)
#ifdef _WIN32
#define long int64_t
#endif
#define fi first
#define se second
#define _UN using namespace
using namespace std;
typedef pair<int,int> pii;
typedef __int128 i128;
namespace std{
template<>
struct hash<pair<int,int>>{
size_t operator()(const pair<int,int>& x)const{ return _Hash_bytes(&x,sizeof(x),0xc70f6907); }
};
}
const int MAXN=1010; const long NINF=0xc0c0c0c0c0c0c0c0;
int mod,fac[MAXN],inv[MAXN],n,m;
long C[MAXN][MAXN];
long F[MAXN][MAXN];
long solve(int k){
if(k==0) return 0;
RNG(j,max(1,m-n/(k+1)-1),m){
F[m-j][0]=1;
RNG(i,1,n) F[m-j][i]=j*(F[m-j][i-1]-(i-1-k<0||j-1<=0?0:F[m-(j-1)][i-1-k])*C[i-1][k]%mod)%mod;
}
return F[m-m][n];
}
void case_main(){
cin>>n>>m;
RNG(i,0,n) fill(F[i],F[i]+n+1,0);
long ans=0,sum=1;
RNG(_,1,n) sum=sum*m%mod;
IRNG(k,n,1){
auto x=solve(k-1);
ans=(ans+(sum-x+mod)*k)%mod;
sum=x;
}
cout<<ans<<"\n";
}
int main(){
#if defined(_LOCAL_)
freopen("in","r",stdin);
// freopen("out","w",stdout);
// freopen("/dev/null","w",stderr);
#else
// freopen("yesterday.in","r",stdin);
// freopen("yesterday.out","w",stdout);
#endif
ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
int cas; cin>>cas>>mod;
auto N=1000;
C[0][0]=1;
RNG(i,1,N){
C[i][0]=1;
RNG(j,1,i) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
}
RNG(_,1,cas) case_main();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 13404kb
input:
3 123456789 3 2 5 5 7 7
output:
18 7145 2066323
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 12804kb
input:
100 2 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 3 1 3 2 3 3 3 4 3 5 3 6 3 7 3 8 3 9 3 10 4 1 4 2 4 3 4 4 4 5 4 6 4 7 4 8 4 9 4 10 5 1 5 2 5 3 5 4 5 5 5 6 5 7 5 8 5 9 5 10 6 1 6 2 6 3 6 4 6 5 6 6 6 7 6 8 6 9 6 10 7 1 7 2 7 3 7 4 7 5 7 6 7 7 7 8 7 9 7 10 8 1 8 2...
output:
1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0
result:
wrong answer 11th lines differ - expected: '0', found: '1'