QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#557295#9254. Random VariablesLarunatrecyWA 2ms9584kbC++141.0kb2024-09-11 08:44:262024-09-11 08:44:31

Judging History

This is the latest submission verdict.

  • [2024-09-11 08:44:31]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 9584kb
  • [2024-09-11 08:44:26]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
template <typename T>inline void read(T &x)
{
    x=0;char c=getchar();bool f=0;
    for(;c<'0'||c>'9';c=getchar())f|=(c=='-');
    for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+(c-'0');
    x=(f?-x:x);
}
const int N = 1020;
int dp[N][N];
int n,m,mod,C[N][N];
void solve()
{
    read(n);read(m);
    int r=0,ans=0;
    for(int k=1;k<=n;k++)
    {
        int lim=min(m,n/(k+1));
        for(int i=0;i<=n;i++)
        for(int j=lim;j>=0;j--)
        if(i<=k)dp[i][j]=(i==0?1:1ll*dp[i-1][j]*(m-j)%mod);
        else if(j<m)dp[i][j]=(1ll*dp[i-1][j]*(m-j)%mod-1ll*(m-j)*C[i-1][k]%mod*dp[i-(k+1)][j+1]%mod+mod)%mod;
        int w=dp[n][0];
        ans=(ans+1ll*k*(w-r+mod)%mod)%mod;r=w;
    }
    printf("%d\n",ans);
}
int main()
{
    int T;
    read(T);read(mod);
    for(int i=0;i<=1000;i++)
    {
        C[i][0]=1;
        for(int j=1;j<=i;j++)
        C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
    }
    while(T--)
    {
        solve();
    }
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 9584kb

input:

3 123456789
3 2
5 5
7 7

output:

18
7145
2066323

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 9236kb

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
0
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
0
0
1
0
1
0
1
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
1
0
1
0
1
0
0
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 31st lines differ - expected: '0', found: '1'