Submission #290682

# Submission time Handle Problem Language Result Execution time Memory
290682 2020-09-04T10:27:29 Z Berted Skyscraper (JOI16_skyscraper) C++14
100 / 100
165 ms 2936 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include <iostream>
#include <algorithm>
#define ll long long
const int MD = 1e9 + 7;
using namespace std;

int n, l, ar[101], dp[2][101][1001][3];

int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> l;
	if (n == 1) {cout << "1\n"; return 0;}
	for (int i = 0; i < n; i++) {cin >> ar[i];}
	sort(ar, ar + n);
	dp[1][1][0][0] = 1;
	dp[1][1][0][1] = 2;
	for (int i = 2; i <= n; i++)
	{
		for (int k = 0; k <= l; k++)
		{
			for (int m = 0; m <= 2; m++) {dp[i & 1][0][k][m] = 0;}
		}
		for (int j = 1; j <= i; j++)
		{
			for (int k = 0; k <= l; k++)
			{
				for (int m = 0; m <= 2; m++)
				{
					int v = ar[i - 1] - ar[i - 2]; dp[i & 1][j][k][m] = 0;
					if (k - (2 * j - 2 - m) * v >= 0) 
					{
						dp[i & 1][j][k][m] = (dp[i & 1][j][k][m] + (ll)(j - m) * dp[~i & 1][j - 1][k - (2 * j - 2 - m) * v][m]) % MD;
					}
					
					if (k - (2 * j - m) * v >= 0) 
					{
						dp[i & 1][j][k][m] = (dp[i & 1][j][k][m] + (ll)(2 * j - m) * dp[~i & 1][j][k - (2 * j - m) * v][m]) % MD; 
					}
					
					if (k - (2 * j + 2 - m) * v >= 0 && j + 1 < i && (j >= m || i == n)) 
					{
						dp[i & 1][j][k][m] = (dp[i & 1][j][k][m] + (ll)j * dp[~i & 1][j + 1][k - (2 * j + 2 - m) * v][m]) % MD;
					}
					
					if (k - (2 * j - m - 1) * v>= 0 && m) 
					{
						dp[i & 1][j][k][m] = (dp[i & 1][j][k][m] + (ll)(3 - m) * dp[~i & 1][j - 1][k - (2 * j - m - 1) * v][m - 1]) % MD;
					}
					if (k - (2 * j - m + 1)  * v>= 0 && m && (j >= m || i == n) && j < i) 
					{
						dp[i & 1][j][k][m] = (dp[i & 1][j][k][m] + (ll)(3 - m) * dp[~i & 1][j][k - (2 * j - m + 1) * v][m - 1]) % MD;
					}
				}
			}
		}
	}
	int res = 0;
	for (int i = 0; i <= l; i++)
	{
		res = (res + dp[n & 1][1][i][2]) % MD;
	}
	cout << res << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 1 ms 640 KB Output is correct
22 Correct 121 ms 2108 KB Output is correct
23 Correct 156 ms 2680 KB Output is correct
24 Correct 136 ms 2680 KB Output is correct
25 Correct 165 ms 2936 KB Output is correct
26 Correct 140 ms 2680 KB Output is correct
27 Correct 51 ms 1656 KB Output is correct
28 Correct 65 ms 1784 KB Output is correct
29 Correct 125 ms 2424 KB Output is correct
30 Correct 160 ms 2684 KB Output is correct