Submission #468133

# Submission time Handle Problem Language Result Execution time Memory
468133 2021-08-26T20:36:33 Z sinamhdv Skyscraper (JOI16_skyscraper) C++11
100 / 100
146 ms 5532 KB
// JOI16_skyscraper
#include <bits/stdc++.h>
using namespace std;

#define int ll

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1e9 + 100;
const ll LINF = 1e18 + 100;

#ifdef DEBUG
#define dbg(x) cout << #x << " = " << (x) << endl << flush;
#define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; }
#else
#define dbg(x) ;
#define dbgr(s, f) ;
#endif
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define fr first
#define sc second
#define all(x) (x).begin(), (x).end()
#define endl '\n'

const int MAXN = 110;
const int MAXL = 1010;

int n, L, a[MAXN];
int dp[2][MAXN][MAXL][3];

inline void relax(int i, int j, int k, int l, ll val)
{
	if (k < 0 || k >= MAXL) return;
	dp[i][j][k][l] = (dp[i][j][k][l] + val) % mod;
}

int32_t main(void)
{
	fast_io;
	cin >> n >> L;
	if (n == 1) return cout << "1\n", 0;

	FOR(i, 1, n + 1) cin >> a[i];
	sort(a + 1, a + n + 1);

	// base
	FOR(k, 0, MAXL)
	{
		dp[1][1][k][0] = 1;
		dp[1][1][k][1] = 1;
	}

	// dp
	FOR(i, 1, n)
	{
		int p = i % 2, c = 1 - p;
		int dif = a[i + 1] - a[i];
		memset(dp[c], 0, sizeof(dp[c]));

		FOR(j, 1, i + 1)
		{
			FOR(k, 0, MAXL)
			{
				relax(c, j + 1, k + 2 * j * dif, 0, (j + 1) * (ll)dp[p][j][k][0]);
				relax(c, j, k + 2 * j * dif, 0, 2 * j * (ll)dp[p][j][k][0]);
				relax(c, j - 1, k + 2 * j * dif, 0, (j - 1) * (ll)dp[p][j][k][0]);

				
				

				relax(c, j + 1, k + (2 * j - 1) * dif, 1, j * (ll)dp[p][j][k][1]);
				relax(c, j + 1, k + 2 * j * dif, 1, dp[p][j][k][0]);
				
				relax(c, j, k + (2 * j - 1) * dif, 1, (2 * j - 1) * (ll)dp[p][j][k][1]);
				relax(c, j, k + 2 * j * dif, 1, dp[p][j][k][0]);
				
				relax(c, j - 1, k + (2 * j - 1) * dif, 1, (j - 1) * (ll)dp[p][j][k][1]);


				

				relax(c, j + 1, k + (2 * j - 2) * dif, 2, (j - 1) * (ll)dp[p][j][k][2]);
				relax(c, j + 1, k + (2 * j - 1) * dif, 2, 2ll * dp[p][j][k][1]);
				
				relax(c, j, k + (2 * j - 2) * dif, 2, (2 * j - 2) * (ll)dp[p][j][k][2]);
				relax(c, j, k + (2 * j - 1) * dif, 2, 2ll * dp[p][j][k][1]);
				
				relax(c, j - 1, k + (2 * j - 2) * dif, 2, (j - 1) * (ll)dp[p][j][k][2]);
			}
		}

		if (i + 1 < n)
		{
			FOR(k, 0, MAXL) dp[c][1][k][2] = 0;
		}
	}

	int ans = dp[n % 2][1][L][2];
	ans = (mod + ans % mod) % mod;
	cout << ans << endl;

	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 2 ms 2892 KB Output is correct
3 Correct 3 ms 5452 KB Output is correct
4 Correct 4 ms 5440 KB Output is correct
5 Correct 4 ms 5452 KB Output is correct
6 Correct 4 ms 5444 KB Output is correct
7 Correct 4 ms 5452 KB Output is correct
8 Correct 5 ms 5452 KB Output is correct
9 Correct 4 ms 5452 KB Output is correct
10 Correct 5 ms 5448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5452 KB Output is correct
2 Correct 7 ms 5452 KB Output is correct
3 Correct 7 ms 5452 KB Output is correct
4 Correct 8 ms 5452 KB Output is correct
5 Correct 7 ms 5452 KB Output is correct
6 Correct 7 ms 5452 KB Output is correct
7 Correct 7 ms 5448 KB Output is correct
8 Correct 8 ms 5452 KB Output is correct
9 Correct 7 ms 5444 KB Output is correct
10 Correct 7 ms 5452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 2 ms 2892 KB Output is correct
3 Correct 3 ms 5452 KB Output is correct
4 Correct 4 ms 5440 KB Output is correct
5 Correct 4 ms 5452 KB Output is correct
6 Correct 4 ms 5444 KB Output is correct
7 Correct 4 ms 5452 KB Output is correct
8 Correct 5 ms 5452 KB Output is correct
9 Correct 4 ms 5452 KB Output is correct
10 Correct 5 ms 5448 KB Output is correct
11 Correct 6 ms 5452 KB Output is correct
12 Correct 7 ms 5452 KB Output is correct
13 Correct 7 ms 5452 KB Output is correct
14 Correct 8 ms 5452 KB Output is correct
15 Correct 7 ms 5452 KB Output is correct
16 Correct 7 ms 5452 KB Output is correct
17 Correct 7 ms 5448 KB Output is correct
18 Correct 8 ms 5452 KB Output is correct
19 Correct 7 ms 5444 KB Output is correct
20 Correct 7 ms 5452 KB Output is correct
21 Correct 29 ms 5452 KB Output is correct
22 Correct 89 ms 5532 KB Output is correct
23 Correct 94 ms 5452 KB Output is correct
24 Correct 124 ms 5452 KB Output is correct
25 Correct 95 ms 5508 KB Output is correct
26 Correct 100 ms 5508 KB Output is correct
27 Correct 142 ms 5508 KB Output is correct
28 Correct 146 ms 5512 KB Output is correct
29 Correct 134 ms 5452 KB Output is correct
30 Correct 95 ms 5452 KB Output is correct