QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#695809 | #9254. Random Variables | real_sigma_team | WA | 2ms | 9528kb | C++23 | 1.3kb | 2024-10-31 20:50:52 | 2024-10-31 20:50:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int mod;
int add(int a, int b) {
return a + b >= mod ? a + b - mod : a + b;
}
int sub(int a, int b) {
return a >= b ? a - b : a + mod - b;
}
int mul(int a, int b) {
return 1ll * a * b % mod;
}
int power(int a, int x) {
int res = 1;
while (x) {
if (x & 1) {
res = mul(res, a);
}
a = mul(a, a);
x >>= 1;
}
return res;
}
constexpr int N = 1010;
int dp[N][N], cnk[N][N];
void solve() {
int n, m;
cin >> n >> m;
int ans = power(m, n);
for (int k = 1; k < n; k++) {
int shift = max(m - n / k - 3, 1);
for (int j = shift; j <= m; j++) {
dp[0][j - shift] = 1;
}
for (int i = 1; i <= n; i++) {
for (int j = shift; j <= m; j++) {
dp[i][j - shift] = mul(j, dp[i - 1][j - shift]);
if (i - k - 1 >= 0 && j - 1 >= shift) {
dp[i][j - shift] = sub(dp[i][j - shift], mul(j, mul(cnk[i - 1][k], dp[i - k - 1][j - 1 - shift])));
}
}
}
ans = add(ans, sub(power(m, n), dp[n][m - shift]));
}
cout << ans << '\n';
}
int32_t main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int t;
cin >> t >> mod;
cnk[0][0] = 1;
for (int i = 1; i < N; i++) {
cnk[i][0] = 1;
for (int j = 1; j < N; j++) {
cnk[i][j] = add(cnk[i - 1][j], cnk[i - 1][j - 1]);
}
}
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9528kb
input:
3 123456789 3 2 5 5 7 7
output:
18 7145 2066323
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 7768kb
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'