이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
using namespace std;
#define ALL(x) x.begin(), x.end()
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
using ll = long long;
#define int long long
const ll M = 1'000'000'007;
int I, n, l, a[101], dp[2][101][1001][3], z, D;
inline int O(int j, int k, int l)
{
k -= (2*j-l) * D;
if (j < 0 || k < 0) return 0;
return dp[!I][j][k][l];
}
signed main()
{
ShinLena;
cin >> n >> l;
for (int i = 1; i <= n; ++i) cin >> a[i];
sort(a+1, a+n+1);
dp[1][1][0][0] = 1;
dp[1][1][0][1] = 2;
for (int i = 2; i <= n; ++i, I ^= 1)
{
D = a[i] - a[i-1];
memset(dp[I], 0, sizeof *dp);
for (int j = 1; j <= i; ++j)
{
for (int k = 1; k <= l; ++k)
{
/* dp[I][j][k][0] */ {
int &d = dp[I][j][k][0];
(d += O(j+1, k, 0) * j % M) %= M;
(d += O(j-1, k, 0) * j % M) %= M;
(d += O(j+0, k, 0) * 2*j % M) %= M;
}
/* dp[I][j][k][1] */ {
int &d = dp[I][j][k][1];
(d += O(j+1, k, 1) * j % M) %= M;
(d += O(j-1, k, 1) * (j-1) % M) %= M;
(d += O(j+0, k, 1) * (2*j-1) % M) %= M;
(d += O(j-1, k, 0) * 2 % M) %= M;
(d += O(j+0, k, 0) * 2 % M) %= M;
}
/* dp[I][j][k][2] */ {
int &d = dp[I][j][k][2];
(d += O(j+1, k, 2) * j % M) %= M;
(d += O(j-1, k, 2) * (j-2) % M) %= M;
(d += O(j+0, k, 2) * (2*j-2) % M) %= M;
(d += O(j-1, k, 1) % M) %= M;
(d += O(j+0, k, 1) % M) %= M;
}
}
}
}
for (int k = 0; k <= l; ++k) (z += dp[n&1][1][k][2] % M) %= M;
cout << z + (n == 1);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |