#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define repi(i,x,y) for(int i = x; i >= y; --i)
#define ci(x) int x; cin>> x
#define TC(t) ci(t); while(t--)
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define cii(x, y) ci(x); ci(y)
#define ciii(x, y, z) ci(x); ci(y); ci(z)
#define mp make_pair
//#define int long long
typedef long long ll;
typedef vector<int> vi;
const int N = 100 + 5;
const int NN = 16 + 15;
const int mod = 1e9 + 7;
const int mod1 = 1e9 + 9;
const int pi = 31;
const ll inf = 1e15 + 6;
const int block = 500;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
void readfile(){
#ifdef ONLINE_JUDGE
#else
freopen("text.inp", "r", stdin);
#endif // ONLINE_JUDGE
// freopen("text.inp", "r", stdin);
// freopen("template.out", "w", stdout);
}
int n, L;
int a[N];
void inp(){
cin >> n >> L;
for(int i = 1; i <= n; ++i) cin >> a[i];
sort(a + 1, a + n + 1);
}
int add(int x, int y){
x += y;
while(x < 0) x += mod;
while(x >= mod) x -= mod;
return x;
}
int mul(int x, int y){
return (x * 1LL * y) % mod;
}
int dp[N][N][N*N][3];
void process(){
dp[1][1][0][0] = 1;
dp[1][1][0][1] = 2;
dp[1][1][0][2] = 1;
for(int i = 1; i < n; ++i){
for(int j = 1; j <= i; ++j){
for(int k = 0; k <= L; ++k){
for(int t = 0; t < 3; ++t){
int val = k + (2*j - t) * (a[i + 1] - a[i]);
if(val > L) continue;
// new cc
dp[i + 1][j + 1][val][t] = add(dp[i + 1][j + 1][val][t], mul(j + 1 - t, dp[i][j][k][t]));
if(t + 1 <= 2)
dp[i + 1][j + 1][val][t + 1] = add(dp[i + 1][j + 1][val][t + 1], mul(dp[i][j][k][t], 2 - t));
// into existing cc
dp[i + 1][j][val][t] = add(dp[i + 1][j][val][t], mul(dp[i][j][k][t], 2*j - t));
if(t + 1 <= 2)
dp[i + 1][j][val][t + 1] = add(dp[i + 1][j][val][t + 1], mul(dp[i][j][k][t], 2 - t));
// merge cc
dp[i + 1][j - 1][val][t] = add(dp[i + 1][j - 1][val][t], mul(dp[i][j][k][t], j - 1));
}
}
}
}
int res = 0;
for(int i = 0; i <= L; ++i)
res = add(res, dp[n][1][i][2]);
cout << res;
}
int main() {
// readfile();
ios_base::sync_with_stdio(0);
cin.tie(0);
// int t; cin >> t;
// while(t--){
inp();
process();
// }
return 0;
}
Compilation message
skyscraper.cpp: In function 'void readfile()':
skyscraper.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen("text.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
844 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
456 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
844 KB |
Output is correct |
10 |
Correct |
1 ms |
580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
716 KB |
Output is correct |
2 |
Correct |
1 ms |
844 KB |
Output is correct |
3 |
Correct |
1 ms |
844 KB |
Output is correct |
4 |
Correct |
1 ms |
716 KB |
Output is correct |
5 |
Correct |
1 ms |
844 KB |
Output is correct |
6 |
Correct |
1 ms |
844 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
844 KB |
Output is correct |
9 |
Correct |
1 ms |
844 KB |
Output is correct |
10 |
Correct |
1 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
844 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
456 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
844 KB |
Output is correct |
10 |
Correct |
1 ms |
580 KB |
Output is correct |
11 |
Correct |
1 ms |
716 KB |
Output is correct |
12 |
Correct |
1 ms |
844 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
716 KB |
Output is correct |
15 |
Correct |
1 ms |
844 KB |
Output is correct |
16 |
Correct |
1 ms |
844 KB |
Output is correct |
17 |
Correct |
1 ms |
716 KB |
Output is correct |
18 |
Correct |
1 ms |
844 KB |
Output is correct |
19 |
Correct |
1 ms |
844 KB |
Output is correct |
20 |
Correct |
1 ms |
716 KB |
Output is correct |
21 |
Correct |
3 ms |
3400 KB |
Output is correct |
22 |
Correct |
143 ms |
41896 KB |
Output is correct |
23 |
Correct |
123 ms |
51892 KB |
Output is correct |
24 |
Correct |
113 ms |
50156 KB |
Output is correct |
25 |
Correct |
124 ms |
52444 KB |
Output is correct |
26 |
Correct |
113 ms |
48264 KB |
Output is correct |
27 |
Correct |
53 ms |
33400 KB |
Output is correct |
28 |
Correct |
65 ms |
36848 KB |
Output is correct |
29 |
Correct |
113 ms |
49760 KB |
Output is correct |
30 |
Correct |
125 ms |
52488 KB |
Output is correct |