#include <bits/stdc++.h>
using namespace std;
//#define FILE_IO
const int mod = 1e9 + 7;
typedef pair<int, int> pii;
typedef pair<pii, pii> p4i;
int N, L;
int v[105];
int dp[105][105][1005][3];
bool inq[105][105][1005][3];
/// dp[i][j][k][e] - first i numbers, j remaining gaps, k cost, e ends are fixed
queue<p4i> q;
void addto(int x, int y, int z, int e, int vl)
{
if(x == 3 && y == 1 && z == 4 && e == 1)
{
x++;
x--;
}
if(x < 0 || y < 0 || z < 0 || e < 0) return;
if(z > L) return;
if(vl == 0) return;
if(y == 1 && e == 0) return;
if(y == 0 && e <= 1) return;
if(x != N && y == 0) return;
if(y > N - x)
return;
dp[x][y][z][e] += vl;
if(dp[x][y][z][e] >= mod) dp[x][y][z][e] -= mod;
if(!inq[x][y][z][e])
{
q.push( { {x, y}, {z, e} } );
inq[x][y][z][e] = 1;
}
}
void brute(int v[])
{
vector<int> p;
for(int i = 1; i <= N; i++) p.push_back(v[i]);
vector< vector<int> > pp[105];
sort(p.begin(), p.end());
int ans = 0;
do
{
int cnt = 0;
for(int i = 1; i < p.size(); i++)
cnt += abs(p[i] - p[i - 1]);
if(cnt <= L) ans++;
pp[cnt].push_back(p);
}while(next_permutation(p.begin(), p.end()));
printf("%d\n", ans);
for(auto x: pp[5])
{
for(auto y: x) printf("%d", y);
printf("\n");
}
}
int main()
{
#ifdef FILE_IO
freopen("1.in", "r", stdin);
freopen("1.out", "w", stdout);
#endif
scanf("%d%d", &N, &L);
for(int i = 1; i <= N; i++) scanf("%d", &v[i]);
sort(v + 1, v + N + 1);
//brute(v);
dp[1][2][0][0] = 1; q.push({ {1, 2}, {0, 0} });
dp[1][1][0][1] = 2; q.push({ {1, 1}, {0, 1} });
int ans = 0;
while(!q.empty())
{
auto x = q.front();
q.pop();
int i = x.first.first;
int j = x.first.second;
int k = x.second.first;
int e = x.second.second;
int nk = k + (v[i + 1] - v[i]) * (2 * j - 2 + e);
int vl = dp[i][j][k][e];
if(nk > L) continue;
if(i == N)
{
if(j == 0 && e == 2 && k <= L)
(ans += dp[i][j][k][e]) %= mod;
continue;
}
/// middle, no fix
addto(i + 1, j + 1, nk, e, (1LL * vl * j) % mod);
/// middle, 1 fix, 1 free
addto(i + 1, j, nk, e, (1LL * vl * (j * 2 - 2 + e)) % mod);
/// middle, 2 fix
addto(i + 1, j - 1, nk, e, (1LL * vl * (j - 2 + e)) % mod);
if(e == 0)
{
/// end, no fix
addto(i + 1, j, nk, e + 1, (2 * vl) % mod);
/// end, fix
addto(i + 1, j - 1, nk, e + 1, (2 * vl) % mod);
}
else if(e == 1)
{
/// end, no fix
addto(i + 1, j, nk, e + 1, vl);
/// end, fix
addto(i + 1, j - 1, nk, e + 1, vl);
}
}
printf("%d\n", ans);
return 0;
}
Compilation message
skyscraper.cpp: In function 'void brute(int*)':
skyscraper.cpp:57:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1; i < p.size(); i++)
^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:78:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &L);
^
skyscraper.cpp:79:51: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i = 1; i <= N; i++) scanf("%d", &v[i]);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
740 KB |
Output is correct |
2 |
Correct |
2 ms |
916 KB |
Output is correct |
3 |
Correct |
2 ms |
916 KB |
Output is correct |
4 |
Correct |
2 ms |
944 KB |
Output is correct |
5 |
Correct |
3 ms |
964 KB |
Output is correct |
6 |
Correct |
2 ms |
968 KB |
Output is correct |
7 |
Correct |
2 ms |
968 KB |
Output is correct |
8 |
Correct |
2 ms |
976 KB |
Output is correct |
9 |
Correct |
3 ms |
1152 KB |
Output is correct |
10 |
Correct |
2 ms |
1152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |