QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#135456 | #6637. Perfect Strings | PlentyOfPenalty | WA | 191ms | 11440kb | C++20 | 1.1kb | 2023-08-05 15:38:40 | 2023-08-05 15:38:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e3+9,mod=1e9+7;
int T,n,c,ans,a[N],fac[N],C[(N<<1)][N],A[N];
inline int inv(int x){
if(x<2)return 1;
return (ll)(mod-mod/x)*inv(mod%x)%mod;
}
void dfs(int u,int s){
if(u==c){
int cur=A[n]*fac[n];
if(s==0){
for(int i=0;i<c;i++)cur=(ll)cur*inv((ll)A[a[i]]*fac[a[i]]%mod)%mod;
ans=(ans+cur)%mod;
// cerr<<">> "<<cur<<endl;
// for(int i=0;i<c;i++)cerr<<a[i]<<" \n"[i+1==c];
}
return;
}
for(int x=0;x<=s;x++){
a[u]=x;
// cerr<<"cho: "<<u<<" "<<x<<endl;
dfs(u+1,s-x);
}
}
int solve(){
ans=0;
for(int i=0;i<=n;i++)A[i]=(ll)C[i<<1][i]*inv(i+1)%mod;
// for(int i=0;i<=n;i++)cerr<<A[i]<<" \n"[i==n];
dfs(0,n);
return ans;
}
int main(){
#ifdef memset0
freopen("G.in","r",stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
fac[0]=1;
for(int i=1;i<N;i++)fac[i]=(ll)fac[i-1]*i%mod;
for(int i=0;i<(N<<1);i++){
C[i][0]=1;
for(int j=1;j<=i&&j<N;j++)C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
}
cin>>T;
while(T--){
cin>>n>>c;
cout<<solve()<<endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 11388kb
input:
2 3 1 2 2
output:
1 6
result:
ok 2 number(s): "1 6"
Test #2:
score: -100
Wrong Answer
time: 191ms
memory: 11440kb
input:
100000 1 1 4 1 5 5 3 5 1 2 5 3 1 1 3 3 5 2 2 1 4 1 5 5 2 3 4 1 3 3 2 5 3 2 4 3 4 4 3 5 3 1 5 2 2 2 4 2 5 4 1 2 3 1 4 5 2 5 5 3 1 5 5 2 3 2 5 2 4 1 1 3 3 2 4 5 2 1 4 1 2 2 1 1 3 5 4 5 2 3 3 5 2 5 2 4 5 4 2 3 1 1 2 1 4 4 1 5 5 4 1 3 5 4 4 5 1 3 1 1 3 3 2 4 2 4 2 1 5 5 1 3 2 3 4 1 4 3 2 4 2 4 4 2 1 1 1...
output:
1 1 45875 455 2 1794 1 78 116 1 1 45875 15 1 78 45 17 400000388 800001614 455 1 116 6 800000051 11524 2 1 4639 45 1794 5 116 17 116 1 3 17 4639 1 1 6 1 455 4639 15 455 45 28 11524 15 1 1 800001614 5 11524 3 11524 4639 3 1 78 28 28 1 45875 3 15 1 400000388 28 28 800000051 1 1 45875 15 800001614 3 1 2...
result:
wrong answer 3rd numbers differ - expected: '71445', found: '45875'