Submission #33190

# Submission time Handle Problem Language Result Execution time Memory
33190 2017-10-22T15:49:02 Z aome Skyscraper (JOI16_skyscraper) C++14
15 / 100
3 ms 5620 KB
#include <bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;

const int N = 105;

int n, m, a[N], f[2][N][N * 10][2][2];

void add(int &x, int y) {
	x += y; if (x >= mod) x -= mod;
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	sort(a + 1, a + 1 + n);
	f[0][0][0][0][0] = 1;
	for (int i = 0; i < n; ++i) {
		bool t = i & 1;
		memset(f[t ^ 1], 0, sizeof f[t ^ 1]);
		for (int j = 0; j <= i; ++j) for (int k = 0; k <= m; ++k) {
			for (int l = 0; l <= 1; ++l) for (int r = 0; r <= 1; ++r) {
				if (!f[t][j][k][l][r]) continue;
				//cout << i << ' ' << j << ' ' << k << ' ' << l << ' ' << r << ' ' << f[t][j][k][l][r] << '\n'; 
				int nk = k + (2 * j - l - r) * (a[i + 1] - a[i]);
				if (nk > m || j < l + r) continue;
				// add l, r
				if (!l) {
					// make new component
					add(f[t ^ 1][j + 1][nk][1][r], f[t][j][k][l][r]);
					// add to start of one component
					add(f[t ^ 1][j][nk][1][r], f[t][j][k][l][r]);
				}
				if (!r) {
					// make new component
					add(f[t ^ 1][j + 1][nk][l][1], f[t][j][k][l][r]);
					// add to end of one component
					add(f[t ^ 1][j][nk][l][1], f[t][j][k][l][r]);
				}
				// add new component != l && r
				add(f[t ^ 1][j + 1][nk][l][r], 1LL * f[t][j][k][l][r] * (j - l - r + 1) % mod);
				// add end to l || add start to r
				if (l) add(f[t ^ 1][j][nk][l][r], f[t][j][k][l][r]);
				if (r) add(f[t ^ 1][j][nk][l][r], f[t][j][k][l][r]);
				// add end || start to components != l && r
				add(f[t ^ 1][j][nk][l][r], 2LL * f[t][j][k][l][r] * (j - l - r) % mod);
				// connect 2 components
				if (j) add(f[t ^ 1][j - 1][nk][l][r], 1LL * f[t][j][k][l][r] * (j - 1) % mod);
			}
		}
	}
	int res = 0;
	for (int i = 0; i <= m; ++i) add(res, f[n & 1][1][i][1][1]);
	cout << res;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 5620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5620 KB Output is correct
2 Correct 0 ms 5620 KB Output is correct
3 Correct 0 ms 5620 KB Output is correct
4 Correct 3 ms 5620 KB Output is correct
5 Correct 3 ms 5620 KB Output is correct
6 Correct 0 ms 5620 KB Output is correct
7 Correct 0 ms 5620 KB Output is correct
8 Correct 3 ms 5620 KB Output is correct
9 Correct 0 ms 5620 KB Output is correct
10 Correct 0 ms 5620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 5620 KB Output isn't correct
2 Halted 0 ms 0 KB -