Submission #35349

# Submission time Handle Problem Language Result Execution time Memory
35349 2017-11-20T13:53:34 Z cheater2k Skyscraper (JOI16_skyscraper) C++14
100 / 100
139 ms 193132 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 110;
const int md = 1e9 + 7;

int n, L;
int a[N];
int f[N][N][1010][2][2];

void add(int &x, int y) { x += y; while(x >= md) x -= md; if (x < 0) x += md; }

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> L;
	if (n == 1) {
		printf("1\n"); return 0;
	}
	for (int i = 1; i <= n; ++i) cin >> a[i];
	sort(a + 1, a + n + 1);
	for (int i = n; i >= 2; --i) a[i] = a[i] - a[i-1]; a[1] = 0;

	f[0][0][0][0][0] = 1;
	for (int i = 0; i < n; ++i) for (int j = 0; j <= i; ++j) for (int s = 0; s <= L; ++s) {
		for (int l = 0; l < 2; ++l) for (int r = 0; r < 2; ++r) {
			int cur = f[i][j][s][l][r]; if (cur == 0) continue;
			int ns = s + (2 * j - l - r) * a[i + 1]; if (ns > L) continue;
			
			// push a[i] to the front or the back of a component
			if (!l) add(f[i + 1][j][ns][1][r], 1LL * cur * (j - (i != n - 1 ? r : 0)) % md);
			if (!r) add(f[i + 1][j][ns][l][1], 1LL * cur * (j - (i != n - 1 ? l : 0)) % md);
			add(f[i + 1][j][ns][l][r], 1LL * cur * (2 * j - l - r) % md);

			// use a[i] to connect two distinct components
			if (j >= 1) add(f[i + 1][j - 1][ns][l][r], 1LL * cur * ((j - l - r) * (j - 1) + (i == n - 1 ? l * r : 0)) % md);

			// create a new component
			if (!l) add(f[i + 1][j + 1][ns][1][r], cur);
			if (!r) add(f[i + 1][j + 1][ns][l][1], cur);
			add(f[i + 1][j + 1][ns][l][r], cur);
		}
	}
	
	int ans = 0;
	for (int s = 0; s <= L; ++s) {
		add(ans, f[n][1][s][1][1]);
	}
	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 193132 KB Output is correct
2 Correct 0 ms 193132 KB Output is correct
3 Correct 0 ms 193132 KB Output is correct
4 Correct 0 ms 193132 KB Output is correct
5 Correct 0 ms 193132 KB Output is correct
6 Correct 0 ms 193132 KB Output is correct
7 Correct 0 ms 193132 KB Output is correct
8 Correct 0 ms 193132 KB Output is correct
9 Correct 0 ms 193132 KB Output is correct
10 Correct 0 ms 193132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 193132 KB Output is correct
2 Correct 0 ms 193132 KB Output is correct
3 Correct 0 ms 193132 KB Output is correct
4 Correct 0 ms 193132 KB Output is correct
5 Correct 0 ms 193132 KB Output is correct
6 Correct 0 ms 193132 KB Output is correct
7 Correct 0 ms 193132 KB Output is correct
8 Correct 0 ms 193132 KB Output is correct
9 Correct 0 ms 193132 KB Output is correct
10 Correct 0 ms 193132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 193132 KB Output is correct
2 Correct 0 ms 193132 KB Output is correct
3 Correct 0 ms 193132 KB Output is correct
4 Correct 0 ms 193132 KB Output is correct
5 Correct 0 ms 193132 KB Output is correct
6 Correct 0 ms 193132 KB Output is correct
7 Correct 0 ms 193132 KB Output is correct
8 Correct 0 ms 193132 KB Output is correct
9 Correct 0 ms 193132 KB Output is correct
10 Correct 0 ms 193132 KB Output is correct
11 Correct 0 ms 193132 KB Output is correct
12 Correct 0 ms 193132 KB Output is correct
13 Correct 0 ms 193132 KB Output is correct
14 Correct 0 ms 193132 KB Output is correct
15 Correct 0 ms 193132 KB Output is correct
16 Correct 0 ms 193132 KB Output is correct
17 Correct 0 ms 193132 KB Output is correct
18 Correct 0 ms 193132 KB Output is correct
19 Correct 0 ms 193132 KB Output is correct
20 Correct 0 ms 193132 KB Output is correct
21 Correct 0 ms 193132 KB Output is correct
22 Correct 139 ms 193132 KB Output is correct
23 Correct 79 ms 193132 KB Output is correct
24 Correct 83 ms 193132 KB Output is correct
25 Correct 79 ms 193132 KB Output is correct
26 Correct 79 ms 193132 KB Output is correct
27 Correct 36 ms 193132 KB Output is correct
28 Correct 49 ms 193132 KB Output is correct
29 Correct 99 ms 193132 KB Output is correct
30 Correct 96 ms 193132 KB Output is correct